登录servlet成功拿到后台返回的0登录成功状态,但是无法跳转到server.jsp页面
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.CourseService;
import service.CourseServiceImpl;
public class LoginServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("username");
String password = request.getParameter("password");
String checkCode = request.getParameter("checkCode");
String msg="";
CourseService csi = new CourseServiceImpl();
int loginStatus = csi.login(name, password);
String kaptchaExpected = (String)request.getSession() .getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
System.out.println(kaptchaExpected);
if(loginStatus==0&&checkCode!=null&&checkCode.equals(kaptchaExpected)) {
request.getServletContext().setAttribute("name", name);
msg="{loginStatus:'0',msg:'登录成功'}";
System.out.println("登录成功");
response.getWriter().print(msg);
request.getRequestDispatcher("/classm/jsp/server.jsp").forward(request, response);
}else {
if(loginStatus==1) {
msg="{loginStatus:'1',msg:'您的用户名或密码不正确!'}";
response.getWriter().print(msg);
}else {
msg="{loginStatus:'-1',msg:'验证码错误!'}";
response.getWriter().print(msg);
}
}
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星