<small id='QURLT'></small><noframes id='QURLT'>

  • <i id='QURLT'><tr id='QURLT'><dt id='QURLT'><q id='QURLT'><span id='QURLT'><b id='QURLT'><form id='QURLT'><ins id='QURLT'></ins><ul id='QURLT'></ul><sub id='QURLT'></sub></form><legend id='QURLT'></legend><bdo id='QURLT'><pre id='QURLT'><center id='QURLT'></center></pre></bdo></b><th id='QURLT'></th></span></q></dt></tr></i><div id='QURLT'><tfoot id='QURLT'></tfoot><dl id='QURLT'><fieldset id='QURLT'></fieldset></dl></div>
    <legend id='QURLT'><style id='QURLT'><dir id='QURLT'><q id='QURLT'></q></dir></style></legend>
    <tfoot id='QURLT'></tfoot>
      <bdo id='QURLT'></bdo><ul id='QURLT'></ul>

        在 Struts2 中使用 Tuckey URL Rewrite 在 URL Rewrite 方面需要帮助

        时间:2023-09-24

            <tbody id='A0Vci'></tbody>
        1. <tfoot id='A0Vci'></tfoot>

          <small id='A0Vci'></small><noframes id='A0Vci'>

          • <bdo id='A0Vci'></bdo><ul id='A0Vci'></ul>
            <i id='A0Vci'><tr id='A0Vci'><dt id='A0Vci'><q id='A0Vci'><span id='A0Vci'><b id='A0Vci'><form id='A0Vci'><ins id='A0Vci'></ins><ul id='A0Vci'></ul><sub id='A0Vci'></sub></form><legend id='A0Vci'></legend><bdo id='A0Vci'><pre id='A0Vci'><center id='A0Vci'></center></pre></bdo></b><th id='A0Vci'></th></span></q></dt></tr></i><div id='A0Vci'><tfoot id='A0Vci'></tfoot><dl id='A0Vci'><fieldset id='A0Vci'></fieldset></dl></div>
                  <legend id='A0Vci'><style id='A0Vci'><dir id='A0Vci'><q id='A0Vci'></q></dir></style></legend>
                  本文介绍了在 Struts2 中使用 Tuckey URL Rewrite 在 URL Rewrite 方面需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想重写基于 Struts2 的应用程序的 URL(目前在开发环境中).我已经搜索过它并找到了关于 Tuckey URL Rewrite 并在我的项目中设置它.现在我希望我的登录 url 目前是 http://localhost:8080/MyProject/loadLogin.action(我在 Struts2 中使用通配符映射)看起来像 http://localhost:8080/登录.下面是我的配置代码:

                  I want to rewrite the URL for my Struts2 based application(currently in development environment). I have searched for it and found about Tuckey URL Rewrite and set it up in my project. Now i want my login url which is currently http://localhost:8080/MyProject/loadLogin.action (I am using Wildcard mapping in Struts2) to look like http://localhost:8080/login. Below is my configuration code:

                  struts.xml:

                  struts.xml:

                  <action name="*Login" method="{1}" class="com.myproject.controller.LoginController"> 
                              <result name="login" type="tiles">mylogin</result>
                         </action>
                  

                  web.xml:

                   <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>DEBUG</param-value>
                              </init-param>
                  </filter>
                  <filter-mapping>
                      <filter-name>UrlRewriteFilter</filter-name>
                      <url-pattern>/*</url-pattern>
                      <dispatcher>REQUEST</dispatcher>
                      <dispatcher>FORWARD</dispatcher>
                  </filter-mapping>
                  
                    <filter>
                        <filter-name>struts2</filter-name>
                        <filter-class>
                           org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
                        </filter-class>
                     </filter>
                     <filter-mapping>
                        <filter-name>struts2</filter-name>
                        <url-pattern>/*</url-pattern>
                     </filter-mapping>
                  

                  现在这里是 urlrewrite.xml 有规则,我不知道我是否正确配置了规则:

                  Now here's the urlrewrite.xml which has the rule and I do not know if I have configured the rule correctly:

                  <?xml version="1.0" encoding="utf-8"?>
                  <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
                          "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
                  
                  <!--
                  
                      Configuration file for UrlRewriteFilter
                      http://www.tuckey.org/urlrewrite/
                  
                  -->
                  <urlrewrite>
                  
                         <rule>
                              <from>^/*</from>
                              <to type="redirect">/login</to>
                          </rule>
                  
                  
                  </urlrewrite>
                  

                  推荐答案

                  要重写此 URL http://localhost:8080/login 你必须将 urlrewrite 过滤器部署到根上下文.但是应用程序在 /MyProject 上下文中运行.您不能将同一应用程序中的两个过滤器部署到同一上下文以执行所需的操作.

                  To rewrite to this URL http://localhost:8080/login you have to deploy urlrewrite filter to the root context. But the application is running at the /MyProject context. You can't have both filters in the same application deployed to the same context to perform desired.

                  重写 URL 的工作原理:首先访问要显示的 URL,然后 urlrewrite 过滤器搜索规则,如果找到匹配项,则执行规则并将请求(默认情况下)转发到隐藏的新 URL为用户.

                  How rewrite URL works: first you access the URL that you want to show, then urlrewrite filter searches the rules and if it find the match the rule is executed and request is forwarded (by default) to the new URL which is hidden for the user.

                  如果您在 type="redirect".html#to" rel="nofollow"><to> 标签会显示新的 URL,因为这意味着

                  If you use type="redirect" in the <to> tag the new URL will show up, because it means

                  匹配此规则的条件"和发件人"的请求将被 HTTP 重定向.这是一样的:HttpServletResponse.sendRedirect([to value]))

                  Requests matching the "conditions" and the "from" for this rule will be HTTP redirected. This is the same a doing: HttpServletResponse.sendRedirect([to value]))

                  要重写 URL,您应该使用在根上下文中部署到应用程序的此规则

                  To rewrite URL you should use this rule deployed to the app at the root context

                  <rule>
                    <from>^/login$</from>
                    <to type="redirect">/MyProject/loadLogin.action</to>
                  </rule>
                  

                  这篇关于在 Struts2 中使用 Tuckey URL Rewrite 在 URL Rewrite 方面需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Struts Action 中的多个入口点(迁移 Struts 2.2.3 -> 2.3.1) 下一篇:如何使用 jQuery Ajax 将 javascript 数组发送到 struts 动作

                  相关文章

                    <bdo id='ldsmq'></bdo><ul id='ldsmq'></ul>
                • <i id='ldsmq'><tr id='ldsmq'><dt id='ldsmq'><q id='ldsmq'><span id='ldsmq'><b id='ldsmq'><form id='ldsmq'><ins id='ldsmq'></ins><ul id='ldsmq'></ul><sub id='ldsmq'></sub></form><legend id='ldsmq'></legend><bdo id='ldsmq'><pre id='ldsmq'><center id='ldsmq'></center></pre></bdo></b><th id='ldsmq'></th></span></q></dt></tr></i><div id='ldsmq'><tfoot id='ldsmq'></tfoot><dl id='ldsmq'><fieldset id='ldsmq'></fieldset></dl></div>
                  <legend id='ldsmq'><style id='ldsmq'><dir id='ldsmq'><q id='ldsmq'></q></dir></style></legend>
                • <small id='ldsmq'></small><noframes id='ldsmq'>

                  <tfoot id='ldsmq'></tfoot>