struts.xml配置路径问题

彩票虫虫 2011-09-25 09:33:34
index.jsp
<form action="login.do" method="post">
<input type="submit" value="提交"/>
</form>

web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,/WEB-INF/struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

struts.xml
<package name="defaultaction" extends="struts-default">
<action name="login" class="com.zpyt.actions.LoginAction">
<result name="success" type="dispatcher">/success.jsp</result>
<result name="fail" type="dispatcher">/error.jsp</result>
</action>
</package>

action
public String execute()throws Exception{
System.out.println("找到累了");
return "success";
}
404异常
type Status report

message /LoginPro/login.do

description The requested resource (/LoginPro/login.do) is not available.



找的我实在是累了一直报这个异常,到底是struts那里配置错了啊主要是点击index里面的提交按钮的时候总是404.
...全文
440 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
阳明 to life 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 xingyue425 的回复:]

引用 19 楼 zhouyuqwert 的回复:

引用 18 楼 xingyue425 的回复:

引用 17 楼 zhouyuqwert 的回复:

这是所有能用的result
Java code

/**
* The action execution was successful. Show result
* view to the end user.
*/
pu……
[/Quote]
好吧 我struts理解不够 帮不上你了
彩票虫虫 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 zhouyuqwert 的回复:]

引用 18 楼 xingyue425 的回复:

引用 17 楼 zhouyuqwert 的回复:

这是所有能用的result
Java code

/**
* The action execution was successful. Show result
* view to the end user.
*/
public static final String SUC……
[/Quote]
呵呵result怎么错了啊好像没必要一定要实现Action借口吧。
阳明 to life 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 xingyue425 的回复:]

引用 17 楼 zhouyuqwert 的回复:

这是所有能用的result
Java code

/**
* The action execution was successful. Show result
* view to the end user.
*/
public static final String SUCCESS = "success";

/**
*……
[/Quote]
你从哪理解的?源代码?书?
如果你是按源代码理解,我想你看得源代码还不够多,最起码result那块完全没看到
如果是书,我想你可以放弃那本书了
这个配置我觉得你先按照正规的配置完了再去理解 要不然像你现在这样瞎撞只会浪费更多时间
彩票虫虫 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 zhouyuqwert 的回复:]

这是所有能用的result
Java code

/**
* The action execution was successful. Show result
* view to the end user.
*/
public static final String SUCCESS = "success";

/**
* The ac……
[/Quote]
我按照理解自己配制的啊我只是想知道哪里错了找了很久了就是找不到,帮帮忙吧呵呵。
阳明 to life 2011-09-25
  • 打赏
  • 举报
回复
这是所有能用的result

/**
* The action execution was successful. Show result
* view to the end user.
*/
public static final String SUCCESS = "success";

/**
* The action execution was successful but do not
* show a view. This is useful for actions that are
* handling the view in another fashion like redirect.
*/
public static final String NONE = "none";

/**
* The action execution was a failure.
* Show an error view, possibly asking the
* user to retry entering data.
*/
public static final String ERROR = "error";

/**
* The action execution require more input
* in order to succeed.
* This result is typically used if a form
* handling action has been executed so as
* to provide defaults for a form. The
* form associated with the handler should be
* shown to the end user.
* <p/>
* This result is also used if the given input
* params are invalid, meaning the user
* should try providing input again.
*/
public static final String INPUT = "input";

/**
* The action could not execute, since the
* user most was not logged in. The login view
* should be shown.
*/
public static final String LOGIN = "login";


你这是从哪找的配置方法 感觉还是找下正规点的书照着配比较好
阳明 to life 2011-09-25
  • 打赏
  • 举报
回复
struts.xml放在src下面,
struts.xml


<package name="defaultaction" extends="struts-default">
<action name="login" class="com.zpyt.actions.LoginAction">
<result name="success" type="dispatcher">/success.jsp</result>
<result name="error" type="dispatcher">/error.jsp</result>
</action>
</package>


web.xml

<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


html
<form action="login.action" method="post">
<input type="submit" value="提交"/>
</form>
彩票虫虫 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 peng_hao1988 的回复:]

跳转路径这样写试试,LoginPro/login.do
[/Quote]


应该不是这样,即使是我也不想选择这种方式,你不觉得这样将项目名称和请求地址绑定的很紧吗?我还真没见过这种方式呵呵,不过谢谢回复。
彩票虫虫 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 abcd_0000 的回复:]

缺少namespace!!!
[/Quote]

namespace有默认值的吧默认好像是"".
彩票虫虫 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 jq_ii_qc 的回复:]

<s:form action="login" method="post">
or
<form action="login.action" method="post">
[/Quote]

哥们不给力啊
还是报这个异常
type Status report

message There is no Action mapped for namespace / and action name login.

description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.

  • 打赏
  • 举报
回复
<s:form action="login" method="post">
or
<form action="login.action" method="post">

彩票虫虫 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wangxf_8341 的回复:]

struts2的配置跟struts1的配置有很大的不同
第一struts2默认是以*.action为后缀的,而且你在web.xml中路径最好配置成/*,你要修改后缀名要在struts.xml中添加一行<constant name="struts.action.extension" value="do" />
第二,若有多个配置文件,只要在struts.xml中这样引用 <include fi……
[/Quote]
谢谢你的回复,不过我现在想知道我是哪里错了,你的回答好像有点不沾边呵呵。
彩票虫虫 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhouyuqwert 的回复:]

web.xml
XML code

<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filte……
[/Quote]
按照你这么改会报另外一个错误:
type Status report

message There is no Action mapped for namespace / and action name login.

description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
所以我才将/*改成*.do
彩票虫虫 2011-09-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhouyuqwert 的回复:]

form那的action写login或者login.action都OK吧
[/Quote]
你说跟没说都一样啊,我就是想知道那里配置错了。
桃园闲人 2011-09-25
  • 打赏
  • 举报
回复
跳转路径这样写试试,LoginPro/login.do
神探狄仁杰 2011-09-25
  • 打赏
  • 举报
回复
缺少namespace!!!
SunnyCoffee 2011-09-25
  • 打赏
  • 举报
回复
web.xml
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
淡定的峰哥 2011-09-25
  • 打赏
  • 举报
回复
struts2的配置跟struts1的配置有很大的不同
第一struts2默认是以*.action为后缀的,而且你在web.xml中路径最好配置成/*,你要修改后缀名要在struts.xml中添加一行<constant name="struts.action.extension" value="do" />
第二,若有多个配置文件,只要在struts.xml中这样引用 <include file="struts-default.xml" />
即可
yexiongMYBH 2011-09-25
  • 打赏
  • 举报
回复
如楼上所说,可能struts2对这个*.do特排斥一样的,我上次也配成*.do就一直报错,连启动都报错。

你换成<url-pattern>/*</url-pattern>,或许就不会出现这个错误了。

然后form的提交里面写成login.action或者login都行。
cscxxx 2011-09-25
  • 打赏
  • 举报
回复
支持楼上直接使用/*就可以了
阳明 to life 2011-09-25
  • 打赏
  • 举报
回复
web.xml

<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
加载更多回复(4)

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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