servlet不能使用
这个是我的servletpublic class UserServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String username = req.getParameter("username");
String password = req.getParameter("password");
User user = new User();
user.setUsername(username);
user.setPassword(password);
if(DAOFactory.getUserDAOImpl().isLogin(user)){
req.getRequestDispatcher("/main.jsp").forward(req, resp);
}
}
public void doAdd(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("操作成功");
String username = req.getParameter("username");
String password = req.getParameter("password");
User user = new User();
user.setUsername(username);
user.setPassword(password);
if(DAOFactory.getUserDAOImpl().Add(user)){
System.out.println("添加成功");
}
}
}
web.xml
<servlet>
<servlet-name>user</servlet-name>
<servlet-class>servlet.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>user</servlet-name>
<url-pattern>/user.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>user</servlet-name>
<url-pattern>/Add.do</url-pattern>
</servlet-mapping>
为什么这个<form action="user.do" method="post">能执行成功
而这个<form action="Add.do" method="post">就不能执行?