mapping struts url to non-struts url

Posted on 2005-04-13
Last Modified: 2008-02-01
I have a struts app that I go to at:
If I submit the page it comes back with errors or goes on to do what it is supposed to do.

I want to change it so that I can go to it without the ".do" at the end.

Right now in my web.xml I have:

So, I figured that I could just add the following:

At first it seemed to work. When I went to
the page looked just like it did before when going to it with the ".do". However, when I submitted the page it didn't submit properly. For some reason the "action" attribute of the <form> no longer is correct.

My form is output using:
    <html:form action="/list/user/account/EditUserAccountSubmit" method="post">
normally it outputs:
    <form name="editUserAccountForm" method="post" action="/know/list/user/account/">
with the new mapping in web.xml it outputs:
    <form name="editUserAccountForm" method="post" action="/know">

Not only that, but ALL of my struts forms stopped working. Every single one of them have an "action" attribute that is just "/know" now (until I take that mapping out of the web.xml). Why would that happen?

Is there a way to map struts urls so that they don't have the ".do"? I'm trying to change all the urls in my app to be future resistant. That means that urls that expose implementation details are a no-no if they can be avoided.
Question by:HappyEngineer
    LVL 29

    Accepted Solution

    >>That means that urls that expose implementation details are a no-no if they can be avoided.
    As .do is the generic suffix for servlets not just struts I don't believe that you are exposing implementation details here but I understand why you would want to.

    >>Is there a way to map struts urls so that they don't have the ".do"?
    I don't know but as some important parts of struts add the suffix for you (such as the path attribute of the action mapping in struts-config.xml) this may be an issue. As Struts does try to validate the html:form tag, i.e. it checks to see that the specified action mapping exists in the struts-config.xml, before it compiles the page, it is obviously succeeding. I would look at your config file for why that html:form tag maps to /know".

    As a less radical option, I would try using a different suffix to "do" in the web.xml and see if this works.



    Author Comment

    "/know" is my webapp context root. So, the form tag is apparently mapping to the context root for some reason.

    I don't mind (much) if later parts of a form submission use implementation specific urls. It unlikely that someone would create a long term bookmark to a page in the middle of a form submission. But, I'd like the initial url to be non-struts.

    I realized I needed to do this when I tried using java server faces. Instead of ".do" it uses ".faces" or ".jsf". If I wanted to reimplement a struts app in jsf then I'd need to map to struts urls or I'd need to change the urls I used to point to the new faces implementation.

    I'd really rather avoid the whole mess and just use implementation independant urls.

    It occurs to me that I could hack this by creating a new servlet and have it forward to the struts app. I think that would be stupid since the web.xml should allow me to just map one thing to another.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    The viewer will learn how to implement Singleton Design Pattern in Java.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now