int Servlets中的值

时间:2014-11-09 09:06:09

标签: servlets

Servlet拒绝我的iD工作,它是来自http://puu.sh/cGvGN/6d29084aec.png的int(这些对于学校来说是假的)

我怎样才能让它发挥作用?我以为我做得对,但Servlet停止工作

会发生什么情况是页面没有加载到ViewStudentSchedule页面,因为id INT不起作用。 (它给我一个空白页)

 @WebServlet(urlPatterns = {"/StudentLoginServlet"})
    public class StudentLoginServlet extends HttpServlet {

        /**
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
         * methods.
         *
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            try (PrintWriter out = response.getWriter()) {
                /* TODO output your page here. You may use following sample code. */


                int iD = Integer.valueOf(request.getParameter("iD")).intValue (); 
                String pw = request.getParameter("pw");
                System.out.println(iD);
                System.out.println(pw);


                Student s1=new Student();
                s1.findDB(iD);


                String fn=s1.getFirstName();
                System.out.println(fn);

                String ln=s1.getLastName();
                System.out.println(ln);

                String pwdb=s1.getPassword();
                System.out.println(pwdb);
                RequestDispatcher rd;

                HttpSession ses1=request.getSession();
                ses1.setAttribute("s1", s1);

                if (pw.equals(pwdb)){
                    rd= request.getRequestDispatcher("/ViewStudentSchedule.jsp");
                    rd.forward(request,response);

                }
                else{
                    rd= request.getRequestDispatcher("/LoginError.jsp");
                    rd.forward(request,response);   

                }

            }
        }

        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        /**
         * Handles the HTTP <code>GET</code> method.
         *
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        }

        /**
         * Handles the HTTP <code>POST</code> method.
         *
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        }

        /**
         * Returns a short description of the servlet.
         *
         * @return a String containing servlet description
         */

        @Override
        public String getServletInfo() {
            return "Short description";
        }// </editor-fold>

    }

问题如下      int iD = Integer.valueOf(request.getParameter(“iD”))。intValue();

0 个答案:

没有答案