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">就不能执行?
搜索更多相关主题的帖子:
servlet
----------------解决方案--------------------------------------------------------
应该可以的啊,一个</servlet>可以对应多个 <servlet-mapping>
你要是把错误贴出来。。我们就能更好的帮你解决
----------------解决方案--------------------------------------------------------
不能执行!!
servlet先初始化后,将request,response参数传递给了service()方法,这个方法会解析你的http请求类型(post or get?),然后就会调用相应的doPost() or doGet()方法去处理这个请求,你这样servlet不能解析出来,它怎么能执行呢?
----------------解决方案--------------------------------------------------------
一个servlet应该可以啊,楼主要不试试再多写一个servlet?
----------------解决方案--------------------------------------------------------