HappyEngineer
asked on
mapping struts url to non-struts url
I have a struts app that I go to at:
/know/list/user/account/Ed itUserAcco unt.do
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:
<servlet-mapping>
<servlet-name>action</serv let-name>
<url-pattern>*.do</url-pat tern>
</servlet-mapping>
So, I figured that I could just add the following:
<servlet-mapping>
<servlet-name>action</serv let-name>
<url-pattern>/list/user/ac count/Edit UserAccoun t</url-pat tern>
</servlet-mapping>
At first it seemed to work. When I went to
/know/list/user/account/Ed itUserAcco unt
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 /EditUserA ccountSubm it" method="post">
normally it outputs:
<form name="editUserAccountForm" method="post" action="/know/list/user/ac count/Edit UserAccoun tSubmit.do ">
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.
/know/list/user/account/Ed
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:
<servlet-mapping>
<servlet-name>action</serv
<url-pattern>*.do</url-pat
</servlet-mapping>
So, I figured that I could just add the following:
<servlet-mapping>
<servlet-name>action</serv
<url-pattern>/list/user/ac
</servlet-mapping>
At first it seemed to work. When I went to
/know/list/user/account/Ed
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
normally it outputs:
<form name="editUserAccountForm"
with the new mapping in web.xml it outputs:
<form name="editUserAccountForm"
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.