我创建了一个简单的登录页面。如果用户输入了正确的用户名和密码,页面将被重定向到成功页面,否则将被重定向到索引页面。在登录页面中,我向 servlet 提供了表单提交操作。一旦 servlet 验证输入,它将分派到相应的 jsp 页面。我的问题是调度后仍然在 url 中的操作名称。这样对吗?
package com.123.www;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Login extends HttpServlet {
private static final long serialVersionUID = 1L;
public Login() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
//PrintWriter out = response.getWriter();
String userName = request.getParameter("username");
String passWord = request.getParameter("password");
RequestDispatcher view = null ;
if((userName=="")&&(passWord==""))
{
view = request.getRequestDispatcher("index.jsp");
}
else
{
HttpSession session = request.getSession(true);
session.setAttribute("name",userName);
view = request.getRequestDispatcher("success.jsp");
}
view.forward(request, response);
}
}