免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1126 | 回复: 4
打印 上一主题 下一主题

关于servlet的问题????? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-03-28 17:13 |只看该作者 |倒序浏览
我的主要的问题是不知道怎么用 表单提交给servlet来处理,我的问提如下:
1,首先我在建了一个Form1.html文件,结构如下:
E:\java\Tomcat 5.0\webapps\examples
           ——————————————— +WEB-INF
                       -----------------------------------+ classes
                                    -----------------------------------Form1.class
                       -------------------------------------web.xml
       ------------------------------------ Form.html
Form1.html文件内容如下:
<html>;
<head>;
<title>;Form.jsp</title>;
</head>;
<center>;
<body bgcolor="#FFFFFF">;
<form method="get" action="http://localhost:8080/examples/Form1" >;
<p>;
name:<input type="text" size="10" name="name">;
<p>;
email:<input type="text" size="10" name="email">;
<p>;
<input type="submit" name="submit" value="ok">;
</form>;
</body>;
</center>;
</html>;
2,Form1.java文件如下:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Form1 extends HttpServlet
{
        public void doSet(HttpServletRequest rs,HttpServletResponse rp)
                                                        throws IOException,ServletException
                {
                        rp.setContentType("text/html";
                        PrintWriter out = rp.getWriter();
                        out.println("<html>;";
                        out.println("<head>;";
                        out.println("<title>;"+"ha"+"</title>;";
                        out.println("</head>;";
                        out.println("<body>;";
                       
                        Enumeration e = rs.getParameterNames();
                        while(e.hasMoreElements())
                        {
                                String key = (String)e.nextElement();
                                String value = rs.getParameter(key);
                                out.println("<p>;";
                                out.println(key+"="+value);
                        }
                        out.println("</body>;";
                        out.println("<html>;";
                        out.close();
                }
}

3,web.xml文件如下:
<?xml version="1.0" encoding="ISO-8859-1"?>;

<!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>;
<display-name>;Welcome to Tomcat</display-name>;
<description>;
Welcome to Tomcat
</description>;
<servlet>;
<servlet-name>;Hello</servlet-name>;
<servlet-class>;Hello</servlet-class>;
</servlet>;

<servlet>;
<servlet-name>;Form1</servlet-name>;
<servlet-class>;Form1</servlet-class>;
</servlet>;

<servlet-mapping>;
<servlet-name>;Hello</servlet-name>;
<url-pattern>;/Hello</url-pattern>;
</servlet-mapping>;

<servlet-mapping>;
<servlet-name>;Form1</servlet-name>;
<url-pattern>;/Form1</url-pattern>;
</servlet-mapping>;

</web-app>;
4,我写的Hello的servlet可以运行,
5,现在的问题是:
下面是tomcat 的提示:
HTTP Status 405 - HTTP method GET is not supported by this URL

--------------------------------------------------------------------------------

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).


--------------------------------------------------------------------------------

Apache Tomcat/5.0.28
谢谢了[/img]

论坛徽章:
0
2 [报告]
发表于 2005-03-28 17:30 |只看该作者

关于servlet的问题?????

在<form action="servlet名字">;
然后可以在servlet处理form 表单提交过来的数据。
hen  jian dan  de

论坛徽章:
0
3 [报告]
发表于 2005-03-28 18:10 |只看该作者

关于servlet的问题?????

我试过了,你说的方法不行!

servlet的名字"Form1"不行!原来的那个已不行!
我的问题是:
HTTP Status 405 - HTTP method GET is not supported by this URL

--------------------------------------------------------------------------------

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).


--------------------------------------------------------------------------------

Apache Tomcat/5.0.28

论坛徽章:
0
4 [报告]
发表于 2005-03-28 20:44 |只看该作者

关于servlet的问题?????

不是 doSet
是doGet

论坛徽章:
0
5 [报告]
发表于 2005-03-29 00:58 |只看该作者

关于servlet的问题?????

[quote]原帖由 "wolfg"]oGet[/quote 发表:



谢谢你了!我真是粗心!
以后应该注意了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP