jsp页面填写表单:
<form action="servlet/LoginSer" method="post">
<input type="text" name="user"><br>
<input type="submit" value="登陆">
</form>
提交后LoingSer进行处理:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
RequestDispatcher requestdi = null;
if(request.getParameter("user").equals("123")){
//李育梅
request.setAttribute("已成功,用户为123", "message");
requestdi = request.getRequestDispatcher("../ok.jsp");
requestdi.forward(request, response);
}else{
response.sendRedirect("../Login.jsp");
}
}
成功后即可跳转。