Struts 2 + urlrewrite 的问题,急,急,急!

dragonsky_w 2011-06-15 02:29:46
最近项目中要用到urlrewrite的技术,可是我按照网上找的资料配置,
当我直接访问 http://localhost:8080/Mysite/html 时确实可以直接链接到 admin/目录下的index.jsp文件,该文件是用户输入用户名密码的表单,但是就在登录的时候即提交表单时,因为要跳转至一个action,结果就不成功,我就郁闷了,各位大哥帮帮忙看看那里的问题……

web.xml代码如下:

<!-- URL Rewrite Filter -->
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Struts 2 Filter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>


WEB-INF/urlrewrite.xml代码如下:

<urlrewrite>

<rule>
<note>
The rule means that requests to /test/status/ will be redirected to
/rewrite-status
the url will be rewritten.
</note>
<from>/test/status/</from>
<to type="redirect">%{context-path}/rewrite-status</to>
</rule>

<outbound-rule>
<note>
The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
the url /rewrite-status will be rewritten to /test/status/.

The above rule and this outbound-rule means that end users should never see the
url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks
in your pages.
</note>
<from>/rewrite-status</from>
<to>/test/status/</to>
</outbound-rule>

<rule>
<from>^/html</from>
<to>/admin/</to>
</rule>

<rule>
<from>^/html/user/login/index.html</from>
<to>/admin/userInfo_userLogin.action</to>
</rule>

</urlrewrite>


admin/index.jsp 代码如下:

<!--
原本应该是:
<form name="loginForm" onsubmit="return checkLogin()" action="userInfo_userLogin.action" method="post">

-->
<form name="loginForm" onsubmit="return checkLogin()" action="user/login/index.html" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="31%" height="35" class="login-text02">用户名:<br /></td>
<td width="69%"><input name="loginName" id="loginName" type="text" size="29" value="admin" style="width:200px;"/></td>
</tr>
<tr>
<td height="35" class="login-text02">密  码:<br /></td>
<td><input name="passWord" id="passWord" type="password" size="30" value="123456" style="width:200px;"/></td>
</tr>
<tr>
<td height="35"> </td>
<td><input type="submit" class="right-button01" value="确认登陆"/>      
<input type="reset" class="right-button02" value="重 置" /></td>
</tr>
<tr>
<td height="35" colspan=2 align="center">            
<span style="color:red;font-size:14px;font-weight:bold;" id="errorMsg">${loginMsg} <% session.removeAttribute("loginMsg"); %> </span></td>
</tr>

</table>
</form>


原本访问 http://localhost:8080/MySite/admin 直接进入登录表单录入界面,在提交表单后,正确跳转后url地址为:
http://localhost:8080/MySite/admin/userInfo_userLogin.action 进入跳转后的页面。

而现在访问 http://localhost:8080/MySite/html 也可以同时进入登录表单录入界面,但是在提交表单后,url地址为:
http://localhost:8080/MySite/user/login/index.html 同时页面报404错误,
说找不到 HTTP Status 404 - /MySite/user/login/index.html

究竟是什么问题,拜托各位大哥帮帮忙解决一哈,谢谢了!!!!
...全文
351 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
dragonsky_w 2011-06-17
  • 打赏
  • 举报
回复
我知道这个apache的rewrite module,虽说现在还不会用,但是现在项目中用的就是Tomcat这个应用服务器,没有办法啊,是不是,到现在还是没有办法解决,郁闷啊……
dragonsky_w 2011-06-16
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 dandan0912 的回复:]
<from>^/test/status/$</from>
试试看
[/Quote]

试过了,没有多大的效果,体验不出来啊……
dragonsky_w 2011-06-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zhou961270 的回复:]
把你的Filter贴出来看看
[/Quote]

我这个Filter不是自己写的,而是下载的 urlrewrite-2.6.0.jar 包,导入后直接使用的,此包的下载地址是 http://tuckey.org/urlrewrite/dist/urlrewritefilter-2.6.zip

具体的代码我已经在上面贴出来了……
dandan0912 2011-06-16
  • 打赏
  • 举报
回复
<from>^/test/status/$</from>
试试看
zhou961270 2011-06-16
  • 打赏
  • 举报
回复
把你的Filter贴出来看看
dragonsky_w 2011-06-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zhou961270 的回复:]
http://yangleilt.iteye.com/blog/699475 去这个地方看看,应该对你有帮助
[/Quote]

但是有的地方我还是不太明白,比如我访问一个index.jsp页面,但是url地址里是不会显示该index.jsp的,这样的话,制订的规则不久没有用了,还有另一种情况,就是动态的访问一个action,即网站首页里面显示的内容都是从数据库中查出来的;

情况如下:
输入访问地址:http://localhost:8080/MySite/showIndex/ 后就进入 showIndex目录下的 index.jsp文件中,该文件内容为:

<script type="text/javascript">
window.location = "showIndex.action?aid=27&bid=19&cid=14&did=17&eid=16";
</script>

在该action执行后跳转后的url地址就变成了 http://localhost:8080/MySite/showIndex/showIndex.action?aid=27&bid=19&cid=14&did=17&eid=16

很容易遭到别人入侵,为了解决这个问题,现在的情况是我想要访问的地址是 http://localhost:8080/MySite/web/ 就进入showIndex目录下的index.jsp页面,然后
执行action,经跳转后我想要 url地址变成http://localhost:8080/MySite/web/***/***/***.html

在这种情况下要如何制订规则呢???? 请教,请教,请教!!!!
loveunittesting 2011-06-16
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 dragonsky_w 的回复:]

引用 14 楼 yys79 的回复:
咋都用jspFilter做rewrite呢?这玩意无疑增加了系统负担,有什么用啊。不过还是帮你顶一下。


听这位大哥的语气,似乎有更好的方法,不妨贴出来分享一下,共同学习嘛……O(∩_∩)O~
[/Quote]
一般网站都是用web服务器做rewrite,比如apache的rewrite module,一般也不会为应用服务器开放80端口的。
Ifnie 2011-06-16
  • 打赏
  • 举报
回复
没用过rulrewrite,帮您顶了
dragonsky_w 2011-06-16
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 yys79 的回复:]
咋都用jspFilter做rewrite呢?这玩意无疑增加了系统负担,有什么用啊。不过还是帮你顶一下。
[/Quote]

听这位大哥的语气,似乎有更好的方法,不妨贴出来分享一下,共同学习嘛……O(∩_∩)O~
loveunittesting 2011-06-16
  • 打赏
  • 举报
回复
咋都用jspFilter做rewrite呢?这玩意无疑增加了系统负担,有什么用啊。不过还是帮你顶一下。
dragonsky_w 2011-06-16
  • 打赏
  • 举报
回复
怎么地就没来人了呢…………………………


顶起……

顶起……
解未知数 2011-06-15
  • 打赏
  • 举报
回复
LZ头像不错
zhou961270 2011-06-15
  • 打赏
  • 举报
回复
http://yangleilt.iteye.com/blog/699475 去这个地方看看,应该对你有帮助
dragonsky_w 2011-06-15
  • 打赏
  • 举报
回复
在线等啊 顶起……
dragonsky_w 2011-06-15
  • 打赏
  • 举报
回复
哎,自己顶起……

81,094

社区成员

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

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