获取java类中的输入值

时间:2014-03-02 11:17:54

标签: java jsp servlets

我有servlet

public class Authentification extends HttpServlet {
    public int id1;
    private static final long serialVersionUID = 1L;
    public HttpSession session;
    Authentification_link auth=new Authentification_link();
    public Integer IdUser;

    public Authentification() {
        super();
    }
    public void init()  {
        Codb co= new Codb();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)   throws ServletException, IOException {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        int IdUser = Integer.valueOf(request.getParameter("id"));
        session.setAttribute("ide", IdUser);

        try {       
        if(auth.authen(IdUser)){
            session.setAttribute("id", IdUser);
            request.getRequestDispatcher("acceuil.jsp").forward(request, response);
                System.out.println("found");}
        else{
            request.getRequestDispatcher("index.jsp").forward(request, response);
                System.out.println("not found");
        }
        } catch (SQLException e) {      
            e.printStackTrace();
        }
    }
    public void doInteret (HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException  {
       IdUser = (Integer) session.getAttribute("IdUser");
       Interets inte= new Interets (IdUser);        
    }
}

用户通过id登录,验证工作正常,但现在我想获得相同用户的ID,因此当用户点击链接时我可以将其包含在此java classe中。为此,我在doInteret中添加了servlet方法,而Interet.java类就是这样:

public class Interets {
    static Statement St ;
    public ResultSet rs;

    public Interets(Integer IdUser) throws SQLException, ServletException, IOException{
        String res=" ";
            try{
            ResultSet result = St.executeQuery("SELECT description FROM interets, avoir, consomateur WHERE avoir.id_interet=interets.id_interets AND avoir.id_user=consomateur.code_bar AND consomateur.code_bar="+IdUser+"");

                ResultSetMetaData resultMeta = (ResultSetMetaData) result.getMetaData();

                while(result.next()){         
                 String Newligne=System.getProperty("line.separator"); 
             for(int i = 1; i <= resultMeta.getColumnCount(); i++){ 
                          res=res+Newligne+result.getObject(i).toString();
                          System.out.println(res);
                     }
            }
            }
        catch (Exception e) {
            System.out.println("Error in Select ");
        }
     }
}

但是我收到了这个错误:

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoSuchMethodError: pack1.Interets.AfficheInteret()Ljava/lang/String;
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

1 个答案:

答案 0 :(得分:0)

尝试更改您的查询并打印它可能是您的查询无法正常工作

          SELECT description FROM interets, avoir, consomateur WHERE      avoir.id_interet=interets.id_interets AND avoir.id_user=consomateur.code_bar AND consomateur.code_bar='"+IdUser+"'");