struts的action能不能带小数点

believefym 2009-12-16 10:50:36
需求就是
需要访问a/b.html,当然实际并不一定要存在这么一个页面,只不过是访问这个url
然后调用相应的Action做逻辑处理即可

jsp:
<html:form action="/a/b.html" method="post">


struts-config.xml
<action path="/a/b.html" type="xxx.MyAction" name="myform">


web.xml
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/a/b.html</url-pattern>
</servlet-mapping>


貌似url有小数点,struts自动把它给过滤掉了,提示这样的错误
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve mapping for action: "/a/b"


谁知道怎么做?
...全文
164 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
luffyke 2009-12-16
  • 打赏
  • 举报
回复
改成下横线吧,不过貌似可以修改什么文件来的
bunrise 2009-12-16
  • 打赏
  • 举报
回复
楼主是否配置了多个<url-pattern>,你的请求目录被其他的配置优先映射了?
guangguang0512 2009-12-16
  • 打赏
  • 举报
回复
虽然不晓得怎样解决,但是关注中。。。
XIANJI858651 2009-12-16
  • 打赏
  • 举报
回复
如此修改试下:
<html:form action="/a/b.do" method="post">
<action path="/a/b" type="xxx.MyAction" name="myform">
web.xml配置自始至终文件不用修改任何东西
BearKin 2009-12-16
  • 打赏
  • 举报
回复
没明白。。
lingar02 2009-12-16
  • 打赏
  • 举报
回复
path里面的逗号 是表示层级的,
/a/b.html 表示 /a/b对象内的html元素 所以报错
你可以用其他符号代替 比如/a/b_html
sunjiyun2007 2009-12-16
  • 打赏
  • 举报
回复
去掉就是了
believefym 2009-12-16
  • 打赏
  • 举报
回复
Firefox没显示全,再贴一下
Cannot retrieve mapping for action: "/a/b"
jumpheightway 2009-12-16
  • 打赏
  • 举报
回复
<action path="/b.html" type="xxx.MyAction" name="myform">
songxiaofeng10 2009-12-16
  • 打赏
  • 举报
回复
学习中
shine333 2009-12-16
  • 打赏
  • 举报
回复
org.apache.struts.chain.commands.InvalidPathException?你代码怎么改的?
shine333 2009-12-16
  • 打赏
  • 举报
回复
如果你前面加了Apache之类,可以直接URL Rewrite啊
believefym 2009-12-16
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 shine333 的回复:]
第二,如果这个 <html:form>中的表单项目不是很多,可以考虑改用html代码来替换 <html:xxx>标签
<form action=" <%=request.getContextPath()>/a/b.html" ...>
<input type="text" name="yourPropertyExpression" value=" <bean:write ... />" />
[/Quote]

<action path="/a/b.html" 
</action>


结果报
org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.



我现在的做法是加了一个servlet专门处理这个url,在servlet再转发到.do
如果struts能搞定,那就最好了
shine333 2009-12-16
  • 打赏
  • 举报
回复
OK,对于排名比我高的,我就不详细解释了。

/a/b.html当成/a/b的问题出在<html:form /> org.apache.struts.taglib.html.FormTag,
doStartTag的时候,需要根据<html:form />的action属性,查找ActionMapping,这个功能在org.apache.struts.taglib.TagUtils
    /**
* Return the form action converted into an action mapping path. The
* value of the <code>action</code> property is manipulated as follows in
* computing the name of the requested mapping:
* <ul>
* <li>Any filename extension is removed (on the theory that extension
* mapping is being used to select the controller servlet).</li>
* <li>If the resulting value does not start with a slash, then a
* slash is prepended.</li>
* </ul>
*/
public String getActionMappingName(String action) {

String value = action;
int question = action.indexOf("?");
if (question >= 0) {
value = value.substring(0, question);
}

int slash = value.lastIndexOf("/");
int period = value.lastIndexOf(".");
if ((period >= 0) && (period > slash)) {
value = value.substring(0, period);
}

return value.startsWith("/") ? value : ("/" + value);
}


LZ要做的,
第一,如果整个工程如web.xml描述的,只有一个Action,那么在struts-config及<html:form/>中,都不要写后缀。
第二,如果这个<html:form>中的表单项目不是很多,可以考虑改用html代码来替换<html:xxx>标签
<form action="<%=request.getContextPath()>/a/b.html" ...>
<input type="text" name="yourPropertyExpression" value="<bean:write ... />" />
第三,还是用.do
liangwansheng 2009-12-16
  • 打赏
  • 举报
回复
学习
flyingfish1987 2009-12-16
  • 打赏
  • 举报
回复
struts.action.extension你有没设置过,看能不能在这个上面动动手脚
直接改成struts.action.extension=*试试看
bunrise 2009-12-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 believefym 的回复:]
引用 7 楼 lxd520123 的回复:
楼主是否配置了多个 <url-pattern>,你的请求目录被其他的配置优先映射了?


是配了两个,但是不是这个问题,错误提示是找不到mapping

其他人说的去掉,改成_之类的,都是有悖于需求的
[/Quote]
他把/a/b.html当成/a/b,这个是找不到mapping,
但是他为什么会把/a/b.html当成/a/b,
如果你其他地方没有映射/a/b,那是不是容器不能识别这个映射
而把他交给默认的映射来处理了呢
chen7788 2009-12-16
  • 打赏
  • 举报
回复
开发中,没有遇到类似的事情, 学习~~~
wangleileo 2009-12-16
  • 打赏
  • 举报
回复
struts是在第一次收到对action 的请求(注意:不包括jsp的请求)时,提取这个请求的url的路径信息,把相应模块的mapping 信息设置到请求中去 。 如果在进入一个模块时,第一次访问的是一个jsp页面,而在这个jsp页面中提交到该模块的一个action ,就会出现找不到action mapping 的情况。这就是因为,在进到这个模块时,访问的是jsp,这个模块的任何一个action 都没有被访问到,所以struts的ActionServlet还没有来得及把这个模块的mapping 设置到请求中,自然找不到该模块的action 。

因此,这就引出一个约定,就是系统中尽量避免对Jsp的直接访问,如果要访问也要通过action 来forward 。 虽然看起来麻烦一点,但是安全性、健壮性都会有所提高。

wenfei208 2009-12-16
  • 打赏
  • 举报
回复
把小数点改成_
加载更多回复(1)

81,091

社区成员

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

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