Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package servlet;
- import java.io.IOException;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import javax.servlet.RequestDispatcher;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.PreparedStatement;
- /**
- * Servlet implementation class Getimage
- */
- @WebServlet("/Getimage")
- public class Getimage extends HttpServlet {
- private static final long serialVersionUID = 1L;
- /**
- * @see HttpServlet#HttpServlet()
- */
- public Getimage() {
- super();
- // TODO Auto-generated constructor stub
- }
- /**
- * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- // TODO Auto-generated method stub
- }
- /**
- * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- Infoutente foto=new Infoutente();
- // mi serve per generare l'errore
- Newuser nw = new Newuser();
- HttpSession session = request.getSession();
- String connectionURL = "jdbc:mysql://localhost:3306/imagesharing";
- Connection connection = null;
- PreparedStatement statement=null;
- ResultSet rs=null;
- String query;
- int codfoto=0;
- String url=null;
- String datacaricamento=null;
- String didascalia=null;
- Integer codealbum=0;
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- connection = (Connection) DriverManager.getConnection(connectionURL , "root", "0000");
- codealbum=Integer.parseInt(request.getParameter("album"));
- foto.setCodupload(codealbum);
- query="select * from foto,album where album.codalbum=foto.codalbum and album.codalbum=?";
- statement=(PreparedStatement) connection.prepareStatement(query);
- statement.setInt(1,codealbum);
- rs = statement.executeQuery();
- while(rs.next()){
- foto.setCodalbum(rs.getInt("codalbum"));
- foto.setCodfoto(rs.getInt("codfoto"));
- foto.setDatacaricamento(rs.getString("datacaricamento"));
- foto.setDidascalia(rs.getString("didascalia"));
- foto.setUrl(rs.getString("url"));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- request.setAttribute("foto",foto);
- RequestDispatcher disp=request.getRequestDispatcher("slider.jsp");
- disp.forward(request, response);
- try {
- rs.close();
- statement.close();
- connection.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment