Servlet没有应用更改

时间:2015-04-26 18:23:47

标签: java jsp tomcat java-ee servlets

首次编译我的Servlet后,服务器无法看到代码中的每个下一次修改。无论我在课堂上写什么,我都会得到相同的输出。我试图在Eclipse中重新配置Tomcat,但这不起作用。 Servlet包含到SQL的连接器,他的工作是从表中获取数据并通过getRequestRispatcher将其发送到.jsp文件,因为我给了方法错误的jsp路径,它给出了一个无法找到文件的异常。但是,即使我改变路径以纠正Servlet就像没有任何改变一样,它仍然会给出相同的异常。

代码:

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Load_table
 */
@WebServlet("/Load_table")
public class Load_table extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Load_table() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            List<Towar> magazyn = accessData();

            request.setAttribute("magazyn", magazyn);

            request.getRequestDispatcher("/WebContent/Main.jsp").include(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }


    public List<Towar> accessData() {

        List<Towar> output = new ArrayList<Towar>();

        final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
        final String DB_URL = "jdbc:oracle:thin:@localhost:1521:xe";


       final String USER = "log";
        final String PASS = "pass";


       Connection conn = null;
       Statement stmt = null;
       try{

          Class.forName(JDBC_DRIVER);


          System.out.println("Connecting to database...");
          conn = DriverManager.getConnection(DB_URL,USER,PASS);



          System.out.println("Creating statement...");
          stmt = conn.createStatement();
          String sql;
          sql = String.format("SELECT * from Towary");
          PreparedStatement prepStat = conn.prepareStatement(sql);

          ResultSet rs = prepStat.executeQuery();


          while(rs.next()){



             output.add(new Towar(rs.getString("Nazwa"), rs.getString("Cena"),
                     rs.getString("Stan")));

          }


          rs.close();
          stmt.close();
          conn.close();
       }catch(SQLException se){

          se.printStackTrace();
       }catch(Exception e){

          e.printStackTrace();
       }finally{

          try{
             if(stmt!=null)
                stmt.close();
          }catch(SQLException se2){
          }
          try{
             if(conn!=null)
                conn.close();
          }catch(SQLException se){
             se.printStackTrace();
          }
       }

       return output;
}

}

1 个答案:

答案 0 :(得分:0)

尝试从tomcat工作目录中删除已部署的应用程序,然后重新启动tomcat并再次部署。您将获得最新的更改。