最近项目中要用到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">密&nbsp;&nbsp;码:<br /></td>
        <td><input name="passWord" id="passWord" type="password" size="30" value="123456" style="width:200px;"/></td>
      </tr>
      <tr>
        <td height="35">&nbsp;</td>
        <td><input type="submit" class="right-button01" value="确认登陆"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <input type="reset" class="right-button02" value="重 置" /></td>
      </tr>
      <tr>
        <td height="35" colspan=2 align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <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究竟是什么问题,拜托各位大哥帮帮忙解决一哈,谢谢了!!!!

解决方案 »

  1.   

    http://topic.csdn.net/u/20110615/14/c1bd02a1-f806-43ba-aa43-63414405617b.html?seed=1985779381&r=73856241#r_73856241
      

  2.   

    http://yangleilt.iteye.com/blog/699475 去这个地方看看,应该对你有帮助
      

  3.   


    但是有的地方我还是不太明白,比如我访问一个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在这种情况下要如何制订规则呢????  请教,请教,请教!!!!
      

  4.   

     <from>^/test/status/$</from>
    试试看
      

  5.   


    我这个Filter不是自己写的,而是下载的 urlrewrite-2.6.0.jar  包,导入后直接使用的,此包的下载地址是 http://tuckey.org/urlrewrite/dist/urlrewritefilter-2.6.zip 具体的代码我已经在上面贴出来了……
      

  6.   

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

  7.   

    一般网站都是用web服务器做rewrite,比如apache的rewrite module,一般也不会为应用服务器开放80端口的。
      

  8.   

    我知道这个apache的rewrite module,虽说现在还不会用,但是现在项目中用的就是Tomcat这个应用服务器,没有办法啊,是不是,到现在还是没有办法解决,郁闷啊……