login.html
<form action="myservlet" method="post">
姓名:<input name="userName" type="text"><br><br>
密码:<input name="pwd" type="password"><br><br>
<input type="submit" value="登录">
</form>
myservlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name=request.getParameter("userName");
String pwd=request.getParameter("pwd");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("用户名是"+name+"密码是:"+pwd);
}
web.xml
<servlet-name>Servlet2</servlet-name>
<servlet-class>servelt.Servlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet2</servlet-name>
<url-pattern>/myservlet</url-pattern>
</servlet-mapping>
更奇怪的是,我原来运行好好的sevlet程序全部不显示
求各位大侠帮忙
首先打个断点,确认是否进了doPost,
其次试试用绝对路径
路径问题,这种情况碰到过,你看下你的html和servlet路径的关系,直接用绝对路径也行,把你action的路径换成:项目名/servelt/Servlet2试试
还是不行,用eclipse和myeclipse都试了,可能是jdk的问题,回头重装试试
路径问题。