You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by pawan <pa...@apar.com> on 2003/05/19 13:03:51 UTC

Another Problem with servlet mapping

Hi,

Tomcat 4.1.24, Win 2000, Oracle 8i

here is my directory structure :-

shyam(which is my context root)
|
|___jsp
|       |____ams
|               |_____<my files in this directory>
|
|___servlets

now let say my url is:

http://localhost:8080/shyam/jsp/ams/viewAccount.jsp

This jsp has a form which actually sends this request to
viewAccountDetail.js... I am using this action :-

action="<%= request.getContextPath()
%>/manageAccount/viewAccountDetail.jsp">

now here "manageAccount" is just a keyword which i am using for url mapping
in my web.xml file....and its calling my controller servlet....which is
working fine. Now this servlet creates an instance of my bean
"AccountData.java" and then i have to forward this request to the actual
"viewAccountDetail.jsp"

http://localhost:8080/shyam/jsp/ams/viewAccountDetails.jsp

to forward i am using :

req.getRequestDispatcher("/jsp/ams/viewAccountDetail.jsp").forward(req,
resp);

Its finding the targeted page as i can see some console output but the url
in the browser doesn't change. It remains
http://localhost:8080/shyam/manageAccount/viewAccountDetail.jsp

Because of this my page is not able to load any images or style sheet.... so
how can i change actual url in the browser address bar????


Please show me a way or an alternate way to achieve this MVC.

Thanks In Advance

Pawan


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Another Problem with servlet mapping

Posted by Bill Barker <wb...@wilshire.com>.
"pawan" <pa...@apar.com> wrote in message
news:025501c31df6$558118b0$c00010ac@atl.mdc.apar.com...
> Hi,
>
> Tomcat 4.1.24, Win 2000, Oracle 8i
>
> here is my directory structure :-
>
> shyam(which is my context root)
> |
> |___jsp
> |       |____ams
> |               |_____<my files in this directory>
> |
> |___servlets
>
> now let say my url is:
>
> http://localhost:8080/shyam/jsp/ams/viewAccount.jsp
>
> This jsp has a form which actually sends this request to
> viewAccountDetail.js... I am using this action :-
>
> action="<%= request.getContextPath()
> %>/manageAccount/viewAccountDetail.jsp">
>
> now here "manageAccount" is just a keyword which i am using for url
mapping
> in my web.xml file....and its calling my controller servlet....which is
> working fine. Now this servlet creates an instance of my bean
> "AccountData.java" and then i have to forward this request to the actual
> "viewAccountDetail.jsp"
>
> http://localhost:8080/shyam/jsp/ams/viewAccountDetails.jsp
>
> to forward i am using :
>
> req.getRequestDispatcher("/jsp/ams/viewAccountDetail.jsp").forward(req,
> resp);
>
> Its finding the targeted page as i can see some console output but the url
> in the browser doesn't change. It remains
> http://localhost:8080/shyam/manageAccount/viewAccountDetail.jsp
>

As it should.  The browser doesn't know or care about what you've done with
a rd.forward :).

> Because of this my page is not able to load any images or style sheet....
so
> how can i change actual url in the browser address bar????
>

If you need to change the actual URL in the browser, then use
response.sendRedirect.  However, for MVC, this is bad-practice.  You should
set your img and stylesheet references to be absolute (e.g.
<img src="<%= request.getContextPath() %>/images/foo.jpg>">).

The (simplified) rule for URLs is:
1)  If it starts with http://server/path then use it verbatum.
2)  Otherwise if it starts with '/....', the use
http://<server>:<port>/....., where <server> and (if not the default port,
port) are copied from the current page.
3) Otherwise, take the URL of the current page, strip off every thing from
the final '/' character, and concatinate the given URL onto it.


>
> Please show me a way or an alternate way to achieve this MVC.
>
> Thanks In Advance
>
> Pawan




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org