当前位置: 代码迷 >> Java Web开发 >> 关于小弟我的Servlet的异常
  详细解决方案

关于小弟我的Servlet的异常

热度:171   发布时间:2016-04-16 21:46:02.0
关于我的Servlet的错误
我做了三个Servlet,第一个是一个登陆界面,第二个是一个控制器,第三个是一个主界面,控制器判断提交用户名和密码后,选择重定向的页面,三个Servlet代码如下,出现了500错误,就是提交用户名和密码后,出现了500错误,而且只能跳转到控制器那个Servlet,希望能告诉我到底出现了什么错误,先谢了
public class LoginServlet extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletExceptionIOException {
//处理字符编码
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
//返回一个界面
out.println("<h1>用户登录</h1>");
out.println("<form action='/UserManager/LoginCLServlet' method='post'>");
out.println("用户名:<input type='text' name='username'><br/>");
out.println("密 码:<input type='password' name='password'><br/>");
out.println("<input type='submit' value='登录' /><br/>");
out.println("</form>");

}

/**
 * The doPost method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);

}

}


public class LoginCLServlet extends HttpServlet {

/**
 * The doGet method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to get.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();

String username = request.getParameter("username");
String password = request.getParameter("password");

if("梁维伟".equals(username) && "123".equals(password)){
response.sendRedirect("/UserManager/MainFrame");
}
else{
response.sendRedirect("/UserManager/LoginServlet");
}
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);

}

}


public class MainFrame extends HttpServlet {

/**
 * The doGet method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to get.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();

out.println("<h1>主界面</h1>");
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);

}

}

------解决思路----------------------
断点跟进去看看哪里出的错?
------解决思路----------------------
com.vv.view.LoginCLServlet
这个是你自己写的类?
看看这个类编译好了没
  相关解决方案