Request isn't Redirecting

Splash Forums Rewrite Users Request isn't Redirecting

This topic contains 3 replies, has 3 voices, and was last updated by  Lincoln Baxter III 2 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #25655

    rahulsoni
    Participant

    Hello All,

    I am facing an issue with redirecting my request. I’m having an URL req:

    <a href="/12/12/tutorial/java"> Tutorial </a>

    So when this anchor is clicked the Request should invoke a Servlet “/MyServlet” ,
    which after some processing forwards the request to a JSP using RequestDispatcher.

    My URL Rewrite is:

    .addRule()
         .perform(Log.message(Level.INFO,"Config File Loaded...."))    
         .addRule(Join.path("/{ID1}/{ID2}/tutorial/.*").to("/MyServlet"))

    but when I’m clicking on the anchor I get a 404 Error stating that the Request Resource could not be found..
    Note: The config file is loaded as the Log msg “Config File Loaded….” gets printed.

    Can someone plz tell me where am I making the error .

    • This topic was modified 2 years, 7 months ago by  rahulsoni.
    • This topic was modified 2 years, 7 months ago by  rahulsoni.
    #25658

    Hey,

    you cannot use regular expressions within the path. You will have to use a parameter instead. Something like this:

    .addRule(Join.path("/{ID1}/{ID2}/tutorial/{something}").to("/MyServlet"))
    

    If you are not interested in the value of something, you can also use:

    .addRule(Join.path("/{ID1}/{ID2}/tutorial/{*}").to("/MyServlet"))
    

    Please also note, that you may have to add the context path to your link if you are not deploying to the root context path of your app server:

    <a href="/myapp/12/12/tutorial/java"> Tutorial </a>
    
    #25659

    rahulsoni
    Participant

    Thanx Christain Sir,

    I don’t get the last point , why we have to add the context path to our link ?????

    When I tried <a href="/clickme"> Tutorial </a> with URL-Rewrite: .addRule(Join.path("/clickme").to("/My_home.jsp"))
    It never worked.

    But when I tried <a href="/My_App/clickme"> Tutorial </a> with same URL-Rewrite, it WORKED.
    HOW??

    And when I put my APP name in the URL it gets appended to the localhost (as I’m deploying it locally now).
    So when I’ll deploy my app on the web,
    my APP’s name will always be appended to the domain name like:
    www.mywebsite.com/My_App/...... Is it so ??????

    If yes, then How can I get rid of my APP name after my Domain name ????

    #25660

    To prevent the Application Context-Root from displaying in the URL, your application must be deployed as the “ROOT” context. Typically this can be done by renaming the .war file to ROOT.war; however, some application servers require XML configuration to enable or set the ROOT context. This is different for each application server.

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

You must be logged in to reply to this topic.

Comments are closed.