struts2-location.href使用404问题

xia929 2014-04-11 11:07:47
使用struts2在location.href这使用出现404问题。
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2].

这是jsp页面代码:
<body>
<form action="login.action">
<input type="text" name="username" ><br>
<input type="password" name="password" ><br>
<input type="submit" value="提交" ><br>
<input type="button" value="查询" onclick="location.href='login!query.action'" >
<input type="button" value="添加" onclick="location.href='login!add.action'" >
<input type="button" value="删除" onclick="location.href='login!delete.action'" >
<input type="button" value="修改" onclick="location.href='login!update.action'" >
</form>
</body>
struts.xml配置文件代码:
<struts>
<package name="default" extends="struts-default">
<action name="login" class="Test.LoginAction" method="execute">
<result name="success">pages/success.jsp</result>
<result name="add">pages/add.jsp</result>
<result name="update">pages/update.jsp</result>
<result name="delete">pages/delete.jsp</result>
<result name="query">pages/query.jsp</result>
</action>
提交按钮能够通过,但是增删改查这四个就不行,为什么?请教各位大神!!
...全文
711 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
xia929 2014-04-20
  • 打赏
  • 举报
回复
引用 14 楼 wlwlwlwl015 的回复:
[quote=引用 13 楼 xia929 的回复:] [quote=引用 12 楼 wlwlwlwl015 的回复:] 1.你把package名改一下,不要起那么特殊。 2.加上namespace="/"。 3.检查一下你Action中的方法名是否正确。 4.确认你没有改项目的默认路径。 其它的确实再看不出来还有什么可能性报这个异常。
那个jsp的 <form action="login.action">的action应该要改为你的那个testone吧。能不能麻烦你有时间帮我看下,实在是没找出问题。。。[/quote] 我没改。我只测试的是4个按钮没问题。我跑过了没发现问题。如果你也找不到问题的话。我把项目发给你你跑一下。如果成功了你再自习对比一下。[/quote] 终于知道原因了,是struts版本的原因,要在配置文件中加入动态调用。。。
小灯光环 2014-04-17
  • 打赏
  • 举报
回复
引用 13 楼 xia929 的回复:
[quote=引用 12 楼 wlwlwlwl015 的回复:] 1.你把package名改一下,不要起那么特殊。 2.加上namespace="/"。 3.检查一下你Action中的方法名是否正确。 4.确认你没有改项目的默认路径。 其它的确实再看不出来还有什么可能性报这个异常。
那个jsp的 <form action="login.action">的action应该要改为你的那个testone吧。能不能麻烦你有时间帮我看下,实在是没找出问题。。。[/quote] 我没改。我只测试的是4个按钮没问题。我跑过了没发现问题。如果你也找不到问题的话。我把项目发给你你跑一下。如果成功了你再自习对比一下。
xia929 2014-04-17
  • 打赏
  • 举报
回复
引用 12 楼 wlwlwlwl015 的回复:
1.你把package名改一下,不要起那么特殊。
2.加上namespace="/"。
3.检查一下你Action中的方法名是否正确。
4.确认你没有改项目的默认路径。
其它的确实再看不出来还有什么可能性报这个异常。

那个jsp的 <form action="login.action">的action应该要改为你的那个testone吧。能不能麻烦你有时间帮我看下,实在是没找出问题。。。
小灯光环 2014-04-16
  • 打赏
  • 举报
回复
1.你把package名改一下,不要起那么特殊。 2.加上namespace="/"。 3.检查一下你Action中的方法名是否正确。 4.确认你没有改项目的默认路径。 其它的确实再看不出来还有什么可能性报这个异常。
小灯光环 2014-04-16
  • 打赏
  • 举报
回复
引用 9 楼 xia929 的回复:
[quote=引用 7 楼 wlwlwlwl015 的回复:]
[quote=引用 4 楼 xia929 的回复:]


[quote=引用 1 楼 jintianhen1 的回复:]
应该是你的struts配置文件的问题


引用 2 楼 huxiweng 的回复:
There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2].

配置问题,你访问的url是什么,项目名称是什么


引用 3 楼 u012724379 的回复:
配置文件struts.xml检查检查,

struts配置文件就是上面贴出来的那些啊 ,就是那个使用onclick="location.href='login!query.action'" >的出错,那个提交按钮的能够通过。。。项目名称就是struts2[/quote]
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2].
你用的是DMI动态方法调用,在名为login的Action访问add()方法。
可是你在struts.xml定义的Action方法名为execute:
<action name="login" class="Test.LoginAction" method="execute">
这就不对了,你要么把execute去掉,要么把method改成add。
你的result的name只是Action中return的出口,而不是你的入口,好好检查一下。[/quote]

把execute去掉这样是不行的,默认的方法也是execute()啊,不写的效果是一样的。还有把method改成add的话四个增删改查这四个button还是没有实现。 不过谢谢你的建议。[/quote]
其实以前只是在书上看过DMI,一直没有实践过,今天就利用你这个问题的机会写了一个小demo测试了一下:
1.jsp代码和你的一样:

<body>
<span style="font-size: 100px;color: red;font-weight: bold;">Struts2 DMI Test</span><br/>
<form action="login.action">
<input type="text" name="username" ><br>
<input type="password" name="password" ><br>
<input type="submit" value="提交" ><br>
<input type="button" value="查询" onclick="location.href='testone!query.action'" >
<input type="button" value="添加" onclick="location.href='testone!add.action'" >
<input type="button" value="删除" onclick="location.href='testone!delete.action'" >
<input type="button" value="修改" onclick="location.href='testone!update.action'" >
</form>
</body>


2.struts.xml代码:

<package name="my01" namespace="/" extends="struts-default">
<action name="testone" class="com.fit.action.TestAction" method="execute">
<result name="success">/result01.jsp</result>
</action>
</package>


3.Action代码:

public class TestAction extends ActionSupport{

public String query(){
System.out.println("This is query method!");
return "success";
}

public String add(){
System.out.println("This is add method!");
return "success";
}

public String delete(){
System.out.println("This is delete method!");
return "success";
}

public String update(){
System.out.println("This is update method!");
return "success";
}
}


4.测试一切正常,上图:




xia929 2014-04-16
  • 打赏
  • 举报
回复
引用 8 楼 gansigandou 的回复:
英文的意思在ActionMap中 找不到/login!add,也就是说你没有给这个入口,你说你的提交<input type="submit" value="提交" ><br>可以执行是因为提交对应的路径是<form action="login.action">所以他找到的就是名称为login的action,这个是存在的所以可以执行。而你的其他的方法指定了不仅是action名称而且指定了这个action对应的执行方法,所以自然找不到了。 解决方法:<action name="login" class="Test.LoginAction" method="execute">把这个配置五个分别对应你的五个按钮。 楼上说的去掉method的方法我觉得不可行,有两个疑问一个是如果去掉有可能还是找不到,如果能找到那么都会走execute方法那么在具体的execute方法中需要判断是哪个按钮的请求(这个难度应该很大)。如果你有什么好的解决方案也可以回复我!
这样好像也不行,还是实现不了。。。你这个五个配置是说加在配置文件里吗?
xia929 2014-04-16
  • 打赏
  • 举报
回复
引用 7 楼 wlwlwlwl015 的回复:
[quote=引用 4 楼 xia929 的回复:] [quote=引用 1 楼 jintianhen1 的回复:] 应该是你的struts配置文件的问题
引用 2 楼 huxiweng 的回复:
There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2]. 配置问题,你访问的url是什么,项目名称是什么
引用 3 楼 u012724379 的回复:
配置文件struts.xml检查检查,
struts配置文件就是上面贴出来的那些啊 ,就是那个使用onclick="location.href='login!query.action'" >的出错,那个提交按钮的能够通过。。。项目名称就是struts2[/quote] HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2]. 你用的是DMI动态方法调用,在名为login的Action访问add()方法。 可是你在struts.xml定义的Action方法名为execute: <action name="login" class="Test.LoginAction" method="execute"> 这就不对了,你要么把execute去掉,要么把method改成add。 你的result的name只是Action中return的出口,而不是你的入口,好好检查一下。[/quote] 把execute去掉这样是不行的,默认的方法也是execute()啊,不写的效果是一样的。还有把method改成add的话四个增删改查这四个button还是没有实现。 不过谢谢你的建议。
gansigandou 2014-04-15
  • 打赏
  • 举报
回复
英文的意思在ActionMap中 找不到/login!add,也就是说你没有给这个入口,你说你的提交<input type="submit" value="提交" ><br>可以执行是因为提交对应的路径是<form action="login.action">所以他找到的就是名称为login的action,这个是存在的所以可以执行。而你的其他的方法指定了不仅是action名称而且指定了这个action对应的执行方法,所以自然找不到了。 解决方法:<action name="login" class="Test.LoginAction" method="execute">把这个配置五个分别对应你的五个按钮。 楼上说的去掉method的方法我觉得不可行,有两个疑问一个是如果去掉有可能还是找不到,如果能找到那么都会走execute方法那么在具体的execute方法中需要判断是哪个按钮的请求(这个难度应该很大)。如果你有什么好的解决方案也可以回复我!
小灯光环 2014-04-15
  • 打赏
  • 举报
回复
引用 4 楼 xia929 的回复:
[quote=引用 1 楼 jintianhen1 的回复:] 应该是你的struts配置文件的问题
引用 2 楼 huxiweng 的回复:
There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2]. 配置问题,你访问的url是什么,项目名称是什么
引用 3 楼 u012724379 的回复:
配置文件struts.xml检查检查,
struts配置文件就是上面贴出来的那些啊 ,就是那个使用onclick="location.href='login!query.action'" >的出错,那个提交按钮的能够通过。。。项目名称就是struts2[/quote] HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2]. 你用的是DMI动态方法调用,在名为login的Action访问add()方法。 可是你在struts.xml定义的Action方法名为execute: <action name="login" class="Test.LoginAction" method="execute"> 这就不对了,你要么把execute去掉,要么把method改成add。 你的result的name只是Action中return的出口,而不是你的入口,好好检查一下。
tony4geek 2014-04-15
  • 打赏
  • 举报
回复
action 里面有对应的方法不。
静山晚风 2014-04-15
  • 打赏
  • 举报
回复
你用的根据不同参数名执行不同方法,不知道你写对没
xia929 2014-04-14
  • 打赏
  • 举报
回复
引用 1 楼 jintianhen1 的回复:
应该是你的struts配置文件的问题
引用 2 楼 huxiweng 的回复:
There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2]. 配置问题,你访问的url是什么,项目名称是什么
引用 3 楼 u012724379 的回复:
配置文件struts.xml检查检查,
struts配置文件就是上面贴出来的那些啊 ,就是那个使用onclick="location.href='login!query.action'" >的出错,那个提交按钮的能够通过。。。项目名称就是struts2
-江沐风- 2014-04-13
  • 打赏
  • 举报
回复
配置文件struts.xml检查检查,
teemai 2014-04-13
  • 打赏
  • 举报
回复
There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2]. 配置问题,你访问的url是什么,项目名称是什么
静山晚风 2014-04-13
  • 打赏
  • 举报
回复
应该是你的struts配置文件的问题

62,634

社区成员

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

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