struts的问题,急啊!!! HTTP 404 - 未找到文件 !!!在线等

java_jing 2004-12-17 01:59:13
本人刚刚接触struts,照书上写了一个示例程序!!!起初遇到一些问题,在google中但能搜到,但这个问题实在是找不到答案,只得麻烦大家了,
写一个createuser.jsp要求输入uid,password,age,之后显示反馈页面viewuser.jsp.其中用到的bean写好均编译通过,User是一个值对象类,UserForm接收表单提交的数据,UserBean封装连接数据库和插入数据操作,UserAction用于执行业务逻辑,其代码如下,
package com.cstmail.login;
import javax.servlet.http.*;
import org.apache.struts.action.*;

public class UserAction extends Action
{

public ActionForward perform(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
{


UserForm f=(UserForm)form;
try
{
UserBean bean=new UserBean();
bean.addUser(f.getUser());
}
catch(Exception e)
{
e.printStackTrace();
}
request.setAttribute("User",f.getUser());
return(mapping.findForward("userCreated"));



}



}
其中struts-config.xml如下:
<struts-config>
<form-beans>
<form-bean name="userForm" type="com.cstmail.login.UserForm"/>
</form-beans>
<global-forwards>
<forward name="userCreated" path="/viewuser.jsp"/>
</global-forwards>
<action-mappings>
<action path="/createuser"
type="com.cstmail.login.UserAction"
name="userForm"
scope="request"
validate="true"
input="/createuser.jsp">
</action>
<forward name="userCreated" path="/viewuser.jsp"/>
</action-mappings>
<message-resources parameter="ApplicationResources"/>
</struts-config>
其中createuser.jsp如下:
<%@ page contentType="text/html;charset=gb2312" language="java" %>
<%@ taglib uri="/struts-bean" prefix="bean"%>
<%@ taglib uri="/struts-html" prefix="html"%>

<html:html locale="true">
<head>
<title>RegUser</title>
<html:base/>
</head>
<body bgcolor="white">
<html:errors/>
<html:form action="createuser.do" method="GET">
<table border="0" width="100%">
<tr>
<th align="right">
UID:
</th>
<td align="left">
<html:text property="user.uid" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<th align="right">
Password:
</th>
<td align="left">
<html:password property="user.password" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<th align="right">
age:
</th>
<td align="left">
<html:text property="user.age" size="30" maxlength="50"/>
</td>
</tr>
<tr>
<td align="right">
<html:submit property="submit" value="Submit"/>
</td>
<td align="left">
<html:reset/>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>

在ie中发出请求,能显示createuser.jsp页面,但提交后出现错误如下:
您要查看的网页可能已被删除、名称已被更改,或者暂时不可用。

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

请尝试以下操作:

如果您已经在地址栏中输入该网页的地址,请确认其拼写正确。

打开 localhost 主页,然后查找指向您感兴趣信息的链接。
单击后退按钮,尝试其他链接。
单击搜索,寻找 Internet 上的信息。



HTTP 404 - 未找到文件
Internet Explorer

实在是不知道是什么原因啊,郁闷中,望高手指点.不胜感激啊,在线等!!!!
...全文
293 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
java_jing 2004-12-20
  • 打赏
  • 举报
回复
我的servlet运行必须打8080端口号,以前配置整合过apache1.3+tomcat5,可以运行jsp,但我发现其不能运行servlet,必须打http://localhost:8080才能运行servlet.

这次我http://localhost:8080/test/creatuser.jsp页面显示正常,但提交后仍然是creatuser.jsp页面.数据也没有插入到数据库中啊,这是怎么加速啊,好奇怪啊,!!!
luoyc21cn 2004-12-19
  • 打赏
  • 举报
回复
建议你把 <global-forwards>
<forward name="userCreated" path="/viewuser.jsp"/>
</global-forwards>中的<forward name="userCreated" path="/viewuser.jsp"/> 去掉
在保证你的jsp在你的web的context path 中
luoyc21cn 2004-12-19
  • 打赏
  • 举报
回复
你的viewuser.jsp所放的位置是不是正确啊!
bp69 2004-12-19
  • 打赏
  • 举报
回复
<action-mappings>
<action path="/createuser"
type="com.cstmail.login.UserAction"
name="userForm" scope="request"
validate="true" input="/createuser.jsp">
不好意思,<html:form action="createuser.do" method="GET" >,这个地方的确是action="createuser.do"
建议你做一下测试,看看问题出在哪:
将 congig中的<forward name="userCreated" path="/viewuser.jsp"/> 改为
<forward name="userCreated" path="/createuser.jsp"/> ,运行,如果还是报错,说明action有问题,如果正常,说明viewuser.jsp有问题

missyouseeyou 2004-12-18
  • 打赏
  • 举报
回复
O,是TOMCAT的WORK工作目录
missyouseeyou 2004-12-18
  • 打赏
  • 举报
回复
我昨天遇到同样的问题,你把TOMCAT工作目录里的有关这个WEB应用的文件夹去掉,然后重新启动TOMCAT,可能就行了,因为它用的可能还是老的哪个编译文件!
tomy_xu_1981 2004-12-18
  • 打赏
  • 举报
回复
在你的UserAction类中用System.out.println()多打得信息看看你的程序运行到了哪里?
java_jing 2004-12-17
  • 打赏
  • 举报
回复
改成<html:form action="createuser.do" method="GET" >后,createuser.jsp正常,但提交后又提示找不到网页了,

createuser.jsp如下
<%@ page contentType="text/html;charset=gb2312" language="java" %>
<%@ taglib uri="/struts-bean" prefix="bean"%>
<%@ taglib uri="/struts-html" prefix="html"%>

<html:html locale="true">
<head>
<title>RegUser</title>
<html:base/>
</head>
<body bgcolor="white">
<html:errors/>
<html:form action="createuser.do" method="GET" >
<table border="0" width="100%">
<tr>
<th align="right">
UID:
</th>
<td align="left">
<html:text property="user.uid" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<th align="right">
Password:
</th>
<td align="left">
<html:password property="user.password" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<th align="right">
age:
</th>
<td align="left">
<html:text property="user.age" size="30" maxlength="50"/>
</td>
</tr>
<tr>
<td align="right">
<html:submit property="submit" value="Submit"/>
</td>
<td align="left">
<html:reset/>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
java_jing 2004-12-17
  • 打赏
  • 举报
回复
去掉 name="form1"后出现如下错误,是不是html:form action="UserAction.do"不对啊


HTTP Status 500 -

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

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Cannot retrieve mapping for action /UserAction
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.createuser_jsp._jspService(createuser_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.servlet.jsp.JspException: Cannot retrieve mapping for action /UserAction
org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:721)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:417)
org.apache.jsp.createuser_jsp._jspx_meth_html_form_0(createuser_jsp.java:178)
org.apache.jsp.createuser_jsp._jspx_meth_html_html_0(createuser_jsp.java:123)
org.apache.jsp.createuser_jsp._jspService(createuser_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.


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

Apache Tomcat/5.0.28
java_jing 2004-12-17
  • 打赏
  • 举报
回复
HTTP Status 500 -

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

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /createuser.jsp(12,0) Attribute name invalid for tag form according to TLD
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:238)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:975)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:696)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:716)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Validator.validate(Validator.java:1475)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:214)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.


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

Apache Tomcat/5.0.28
bp69 2004-12-17
  • 打赏
  • 举报
回复
你也可以直接把地址改一下:.../createuser.jsp--->...../viewuser.jsp
bp69 2004-12-17
  • 打赏
  • 举报
回复
UserBean,com.cstmail.login.UserForm,还有createduser.jsp,也贴出来看一下
bp69 2004-12-17
  • 打赏
  • 举报
回复
package com.cstmail.login;
import javax.servlet.http.*;
import org.apache.struts.action.*;


public class UserAction extends Action
{

public ActionForward perform(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
{
UserForm f=(UserForm)form;
try
{
UserBean bean=new UserBean();
bean.addUser(f.getUser());
}
catch(Exception e)
{
e.printStackTrace();
}
request.setAttribute("User",f.getUser());
return(mapping.findForward("userCreated"));
}
}
其中struts-config.xml如下:
<struts-config>
<form-beans>
<form-bean name="userForm" type="com.cstmail.login.UserForm"/>
</form-beans>

<action-mappings>
<action path="/createuser" type="com.cstmail.login.UserAction"
name="userForm" scope="request"
validate="true" input="/createuser.jsp">
<forward name="userCreated" path="/viewuser.jsp"/>
</action>
</action-mappings>
<message-resources parameter="ApplicationResources"/>
</struts-config>
其中createuser.jsp如下:
<%@ page contentType="text/html;charset=gb2312" language="java" %>
<%@ taglib uri="/struts-bean" prefix="bean"%>
<%@ taglib uri="/struts-html" prefix="html"%>

<html:html locale="true">
<head>
<title>RegUser</title>
<html:base/>
</head>
<body bgcolor="white">
<html:errors/>
<html:form action="UserAction.do" method="GET" name="form1">
<table border="0" width="100%">
<tr>
<th align="right">
UID:
</th>
<td align="left">
<html:text property="user.uid" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<th align="right">
Password:
</th>
<td align="left">
<html:password property="user.password" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<th align="right">
age:
</th>
<td align="left">
<html:text property="user.age" size="30" maxlength="50"/>
</td>
</tr>
<tr>
<td align="right">
<html:submit property="submit" value="Submit"/>
</td>
<td align="left">
<html:reset/>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
java_jing 2004-12-17
  • 打赏
  • 举报
回复
对,tomcat5了,提示如下:

找不到网页
您要查看的网页可能已被删除、名称已被更改,或者暂时不可用。

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

请尝试以下操作:

如果您已经在地址栏中输入该网页的地址,请确认其拼写正确。

打开 localhost 主页,然后查找指向您感兴趣信息的链接。
单击后退按钮,尝试其他链接。
单击搜索,寻找 Internet 上的信息。



HTTP 404 - 未找到文件
Internet Explorer

bp69 2004-12-17
  • 打赏
  • 举报
回复
是没有找到文件吗,你用的是什么服务器,tomcat?
java_jing 2004-12-17
  • 打赏
  • 举报
回复
刚才试过了,还是不好使啊,愁人啊!!!
java_jing 2004-12-17
  • 打赏
  • 举报
回复
先谢谢了
bp69 2004-12-17
  • 打赏
  • 举报
回复
<html:form action="UserAction.do" method="GET">
bp69 2004-12-17
  • 打赏
  • 举报
回复
<action path="/createuser"------〉path="/UserAction"
type="com.cstmail.login.UserAction"
name="userForm"
scope="request"
validate="true"
input="/createuser.jsp">
</action>
java_jing 2004-12-17
  • 打赏
  • 举报
回复
怎没人回呢,等待中!!!
加载更多回复(4)

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧