Rewrite with Struts2

Splash Forums Rewrite Users Rewrite with Struts2

This topic contains 6 replies, has 3 voices, and was last updated by  Christian Kaltepoth 2 years, 6 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #25789

    rahulsoni
    Participant

    Hi Lincoln/Christian Sir,

    I’m using OCP Rewrite in my application, everything is going well but I want to use Struts2 Framework in my application. Now I have some URLs mapped with URL Rewrite while some URLs have Struts2 Action mapped to appropriate action classes using Struts.xml.

    Now when run my app’n , the Action URLs are all getting executed properly but when I click on the URL mapped with URL-Rewrite I get the following Error Messsage:

    There is no Action mapped for namespace / and action name “abcd.html”

    (abcd.html is the URL which I’ve mapped to another .jsp)

    In my web.xml, I’ve called out filters:

    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

    <filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.ocpsoft.rewrite.config.ConfigurationProvider</filter-class>
    </filter>

    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    </filter-mapping>

    <filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    </filter-mapping>

    Is this right??
    When I exclude the Rewrite filter my app runs but upon inclusion it doesn’t….

    How can I make both Struts2 Actions and my non-Action Rewritten URLs work together ?????

    #25790

    I believe that RewriteFilter should go before StrutsFilter.

    Additionally, your filter definition is incorrect:

    <filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.ocpsoft.rewrite.config.ConfigurationProvider</filter-class>
    </filter>

    should be

    <listener>
       <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletRequestListener</listener-class>
    </listener>
    
    <listener>
       <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletContextListener</listener-class>
    </listener>
    
    <filter>
       <filter-name>OCPsoft Rewrite Filter</filter-name>
       <filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
       <async-supported>true</async-supported>
    </filter>
    <filter-mapping>
       <filter-name>OCPsoft Rewrite Filter</filter-name>
       <url-pattern>/*</url-pattern>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       <dispatcher>ASYNC</dispatcher>
       <dispatcher>ERROR</dispatcher>
    </filter-mapping>

    Which is described in our manual here:

    http://ocpsoft.org/rewrite/docs/configuration/install

    #25791

    rahulsoni
    Participant

    Hi Sir,

    When I run my project the struts mapped actions are working as usual but when I click on the link whose URL is being rewritten I’m getting the following error msg:

    HTTP Status 500 – The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.

    Also when I include : <async-supported>true</async-supported> , my eclipse editor displays following error msg :
    MSG: cvc-complex-type.2.4.a: Invalid content was found starting with element ‘async-supported’. One of ‘{“http://java.sun.com/xml/ns/javaee&#8221;:init-param}’ is expected.

    Is it mandatory to include this param in web.xml , does its exclusion causes any error ??

    Thanks in advance 🙂

    • This reply was modified 2 years, 6 months ago by  rahulsoni.
    #25793

    rahulsoni
    Participant

    Hi,

    Is there also a way to rewrite the action URL that is being displyed in address bar.
    Like:
    http://localhost:8080/My_Struts2/radioUI.action can be displayed as:
    http://localhost:8080/UI_Tags_01/radioUI

    I’ve added following rule but didn’t work….
    .addRule(Join.path("/radioUI.action/.*").to("/radioUI"))

    Also my actions are invoking properly but the anchor links whom I’m rewriting aren’t.
    Like:
    <s:a href="/My_Struts2/abcd">ABCD</s:a>
    To:
    .addRule(Join.path("/abcd").to("/radioUI.jsp"))

    Error Msg: HTTP Status 500 – The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.

    Plz let me know if there is any mistake in d way I’m using Rewrite with Struts-2.

    Thanks

    #25794

    I’m not familiar with Struts 2 so I’m not sure if I can help your very much.

    However, this one won’t work:

    .addRule(Join.path("/radioUI.action/.*").to("/radioUI"))
    

    You cannot use regular expressions in the path. You have to use a parameter instead:

    .addRule(Join.path("/radioUI.action/{whatever}").to("/radioUI"))
    .where("whatever").matches(".*")
    

    This way the value of the parameter will be transformed into a query parameter with the same name.

    #25796

    rahulsoni
    Participant

    Thanks Christain Sir,

    But I’m having one MAJOR Problem while implementing URL Rewrite with Struts2 and that is my Struts Actions are invoking properly but the normal Anchor links that are being redirected as per Configuration RULE are generating following Error:

    Links: <s:a href="/My_Struts2/abcd">ABCD</s:a>
    Rule: .addRule(Join.path("/abcd").to("/radioUI.jsp"))

    Error:
    HTTP Status 500 – The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.

    How can i make URL Rewrite and Struts2 Actions work together ?????

    I’ve added URL Rewrite Filter before Struts Filter.

    Thanks in advance ……

    #25799

    As I already said I’m not familiar with Struts2 and therefore I don’t know how Anchor links in struts work.

    Could you post your web.xml?

    A minimal Maven application to reproduce this error would also be very helpful.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Comments are closed.