通过form把input中的值传到servlet中出错,servlet测试过是正常的。运行以后显示错误为:
405 POST not supported
--------------------------------------------------------------------------------
Resin-3.0.15 (built Wed, 16 Nov 2005 11:15:43 PST)
<!--Sayhi.html
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sayhi.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form name="form1" method="post" action="servlet/Sayhi">
<input type="text" name="Sayhi">
<input type="submit" value="submit">
<input type="reset" value="reset">
</form>
</body>
</html><!--web.xml
-->
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>Sayhi</servlet-name>
<servlet-class>servlet.Sayhi</servlet-class>
<init-param>
<param-name>user</param-name>
<param-value>getInitParameter</param-value>
</init-param>
</servlet> <servlet-mapping>
<servlet-name>Sayhi</servlet-name>
<url-pattern>/servlet/Sayhi</url-pattern>
</servlet-mapping>
</web-app>
//Sayhi.javapackage servlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;public class Sayhi extends HttpServlet
{
String initInfo;
public void init(ServletConfig config)throws
ServletException{
super.init(config);
initInfo = config.getInitParameter("user");
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)throws
ServletException,IOException{
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
out.println("<html><head><title></title></head>");
out.println("<body>" + request.getParameter("Sayhi"));
out.println("</body></html>");
out.close();
}
public String getServletInfo(){
return "servlet.Sayhi Information";
}
public void destory(){}
}
405 POST not supported
--------------------------------------------------------------------------------
Resin-3.0.15 (built Wed, 16 Nov 2005 11:15:43 PST)
<!--Sayhi.html
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sayhi.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form name="form1" method="post" action="servlet/Sayhi">
<input type="text" name="Sayhi">
<input type="submit" value="submit">
<input type="reset" value="reset">
</form>
</body>
</html><!--web.xml
-->
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>Sayhi</servlet-name>
<servlet-class>servlet.Sayhi</servlet-class>
<init-param>
<param-name>user</param-name>
<param-value>getInitParameter</param-value>
</init-param>
</servlet> <servlet-mapping>
<servlet-name>Sayhi</servlet-name>
<url-pattern>/servlet/Sayhi</url-pattern>
</servlet-mapping>
</web-app>
//Sayhi.javapackage servlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;public class Sayhi extends HttpServlet
{
String initInfo;
public void init(ServletConfig config)throws
ServletException{
super.init(config);
initInfo = config.getInitParameter("user");
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)throws
ServletException,IOException{
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
out.println("<html><head><title></title></head>");
out.println("<body>" + request.getParameter("Sayhi"));
out.println("</body></html>");
out.close();
}
public String getServletInfo(){
return "servlet.Sayhi Information";
}
public void destory(){}
}
解决方案 »
- 自动填充页面
- 高手请进..
- linux的jasper报表出错!!
- 安装apache出现的问题(重复安装一次后就这样了)!————解决问题者得满分
- 写ResultSet对象问题
- 用连接池连接Oracle时出现了错误,望大神们解决。。
- 如何保存论坛里的帖子?csdn采用xml难道不能保存为htm?
- 在jsp中的超链接问题
- 数据库发生NullPointerException错误
- 我JSP使用JDBC-ODBC桥,环境WIN2K,JDK1.3,TOMCAT。 如果将来要移植到UNIX上,应该把JDBC-ODBC桥替换为怎样设置
- 在jsp页面中调用javabean的问题
- 互联网和web(基于web)是等同的概念吗?如果不是,它们有什么不一样?非常感谢!
// /////// <form name="form1" action="servlet/Sayhi">
doGet()..也可以
public void doPost(HttpServletRequest request,HttpServletResponse response)throws
ServletException,IOException{
doGet(request,response);
}