1
public class ExtractProduct extends HttpServlet
{
private static final long serialVersionUID = 1L;
public ExtractProduct() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("bye");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("hiiiii");
}
}
JSP页面中的原因:我没有得到,为什么不执行POST方法
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form name="displayProduct" method='post' action='ExtractProduct.do' >
<input type="submit" value="submit"></input>
</form>
</body>
</html>
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
<display-name>adsfa</display-name>
<servlet>
<servlet-name>ExtractProduct</servlet-name>
<display-name>ExtractProduct</display-name>
<description></description>
<servlet-class>
controller.ExtractProduct</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ExtractProduct</servlet-name>
<url-pattern>/ExtractProduct.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
当我点击提交按钮的url模式被改变,它将其重定向到Extractproduct.do,但“hii”不会打印到控制台。任何人都可以帮助我。 我没有得到为什么不执行post方法的原因。
然后我试图创建新的servlet,当我试图运行servelet时,它向我显示一个错误: HTTP状态500 内部服务器错误。 虽然我所有的旧的servelet程序运行正常。
“hii”未打印到控制台“ - 您为什么期望将任何内容打印到控制台?控制台如何与web服务相关? – alfasin
我的主要目的不是在控制台中打印“hii”,我只是想确保执行doPost方法。 – Prasenjit
而不是试图打印到控制台,尝试重定向到一个网页,看看是否发生重定向。例如:'response.sendRedirect(“http://www.google.com”);' – alfasin