一个处理表单提交的servlet的问题。

sharegaozhe 2004-10-23 02:07:09
我是一个初学者,在tomcat中自己创建了一个虚拟目录myapp,并在其中配置好了WEB-INF及其它相关文件。现在可以访问,也可以通过javaBean调用classes中自己写的类。但是当我想自己写一个处理form提交过来的信息的class时,总是报找不到Reg。请大家帮忙分析!!!
源码如下:
jsp文件:
<form name="register1" action="Reg" method="post" onSubmit="return isValid(this);">
<tr>
<td>用户名:</td>
<td><input name="username" type="text" size="18"></td>
</tr>
<tr>
<td>密码:</td>
<td><input name="password" type="password" size="19"></td>
</tr>
<input type="submit" name="Submit2" value="提交">
<input type="reset" name="Submit" value="重置">
</form>

后台的servlet为Reg.class,放在WEB-INF/classes/mypackage下。
并在web.xml中加入:
<servlet>
<servlet-name>Reg</servlet-name>
<servlet-class>library.Reg</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Reg</servlet-name>
<url-pattern>/Reg</url-pattern>
</servlet-mapping>



...全文
115 点赞 收藏 12
写回复
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
michaelyan 2004-10-25
HTTP method POST is not supported by this URL
那可能是你的servlet写的有问题了,应该用doPost(),而不是用doGet(),试试看如何。
回复
chenchen1108 2004-10-25
doGet(),init(),destroy()方法都没有啊?
回复
brozek 2004-10-25
library.Reg中,library就是我的包
上面人家不是说的很清楚啦,把你包里面的全部package都写全了啊.比如com.xxx.xxx.
回复
yuaoyao 2004-10-25
试试把你表单的action改为/servlet/Reg
回复
sharegaozhe 2004-10-25
package library;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import library.*;
public class Reg extends HttpServlet{


public void dopost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

String username=new String(req.getParameter("username").getBytes("ISO8859_1"));
String password= req.getParameter("password");
String studcode=new String(req.getParameter("studcode").getBytes("ISO8859_1"));
String email=new String(req.getParameter("email").getBytes("ISO8859_1"));
String department=new String(req.getParameter("department").getBytes("ISO8859_1"));

String sql="insert into luer(username,password,degree,studcode,email,department) "+
"VALUES('"+username+"','"+password+"',0,'"+studcode+"','"+email+"','"+department+"')";
DataConn myconn =new DataConn();//DataConn是我的另一个class,用来连接数据库的。

myconn.executeInsert(sql);
}









public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {


req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/logout.jsp");
rd.forward(req, res);
}




}


这时在我的源码,请大家帮我看看哪里错了??
回复
sharegaozhe 2004-10-24
我按上面说的改成action="./Reg"后,报错为:

HTTP Status 405 - HTTP method POST is not supported by this URL

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

type Status report

message HTTP method POST is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).
回复
sharegaozhe 2004-10-24
library.Reg中,library就是我的包
回复
wwwer1 2004-10-24
看看你的server.xml里面的配置
有可能是这个问题
http://community.csdn.net/Expert/topic/3462/3462230.xml?temp=.3916284
回复
tutor666 2004-10-24
class里 package mypackage
web.xml里 <servlet-class>mypackage.Reg</servlet-class>
回复
sharegaozhe 2004-10-24
仍旧报错:

HTTP Status 404 - /Reg

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

type Status report

message /Reg

description The requested resource (/Reg) is not available.

回复
umbrella1984 2004-10-23
1:<form name="register1" action="/Reg" method="post" onSubmit="return isValid(this);">

2:
<servlet>
<servlet-name>Reg</servlet-name>
<servlet-class>mypackage.Reg</servlet-class>//包名
</servlet>
<servlet-mapping>
<servlet-name>Reg</servlet-name>
<url-pattern>/Reg</url-pattern>
</servlet-mapping>
回复
dropship 2004-10-23
action="Reg"

改为:
action="/Reg"
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告