4
回答
tomcat 表单提交没反应
华为云实践训练营,热门技术免费实践!>>>   
HelloWorldSerlet.java 代码:

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class HelloWorldSerlet extends HttpServlet{


protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
/*super.doGet(req, resp);*/

PrintWriter out=resp.getWriter();
out.println("<html><head><title>hello world.</title></head><body>Hello World!!!</body></html>");
out.flush();
out.close();
System.out.println("doget...");
}


protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("dopost...");
doGet(req,resp);
}

}






web.xml 文件:






<?xml version="1.0" encoding="ISO-8859-1"?>


<web-app xmlns=" http://java.sun.com/xml/ns/javaee "
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "
version="3.0"
metadata-complete="true">


<servlet>
<servlet-name>hh</servlet-name>
<servlet-class>HelloWorldSerlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hh</servlet-name>
<url-pattern>/HelloWorldSerlet</url-pattern>
</servlet-mapping>
</web-app>


_______________________________________________________________________


更目录下静态index.html文件
<html>
<body>
<from action= http://127.0.0.1:8080/my/HelloWorldSerlet  method=get>
<input type=text name=test>
<input type=submit value="提交">
</from>
</body>
</html>
——————————————————————————————————----——————————
mothod=post同样点击提交没任何反应,具体指页面不跳转,后台不输出。。
浏览器直接访问 http://127.0.0.1:8080/my/HelloWorldSerlet 能正常显示且tomcat输出doget...。
谢!
举报
顶部