aspose file tools*
The moose likes Servlets and the fly likes url-mapping:  Process.jsp to Process servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "url-mapping:  Process.jsp to Process servlet" Watch "url-mapping:  Process.jsp to Process servlet" New topic
Author

url-mapping: Process.jsp to Process servlet

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Pretty basic, but I just wanted to make sure this is standard: say I have a JSP called Process.jsp and a servlet called Process. Is this a good thing to do in my web.xml:

<servlet-mapping>
<servlet-name>Process</servlet-name>
<url-pattern>/Process.jsp</url-pattern>
</servlet-mapping>

If I do this, then any attempts to reach Process.jsp have to go through the Process servlet first. I know the concept is pretty basic, but I was just wondering if I should be doing this a different way, or if there was a reason I wouldn't want to do it like this. Thanks...
[ May 03, 2005: Message edited by: Stephen Huey ]
Jason Kwok
Ranch Hand

Joined: Mar 31, 2005
Posts: 126
I could be mistaken, I'm far from an expert in java, but it seems to me that doing that will in fact direct any request from Process.jsp to the Process servlet instead.

The only problem I could see is that you'll never be able to get to Process.jsp because any get or post to that will always call the servlet instead.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

Jason is correct. The mapping will not have the effect you desire.

Rather, you should forward to the JSP from the servlet using the request dispatcher.

One way to ensure that your JSP pages are never called directly is to place them in a folder structure under the WEB-INF folder.
[ May 03, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
My intention was to never post to the JSP directly...so if I have a post from Process.jsp, I would always post to the Process servlet, and the Process servlet would always eventually forward to the JSP (and any GET requests would also go through the servlet in the same fashion). That's why I mapped the URL Process.jsp to the Process servlet--so that the JSP wouldn't typically be invoked directly and also because I wanted /Process.jsp to show up in the address bar and not /Process alone.

But if it's better not to do this, then I can just change it so that /Process is the last thing in the URL in the address bar.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

I think that'd be best. It seemed to me a very odd thing to be doing, and likely to bite you when you least expect it. (And certainly not standard or customary).

I also tend not to worry too much about what shows up in the address bar.
Giovanni De Stefano
Ranch Hand

Joined: Aug 17, 2004
Posts: 150
Hi,

if your problem is to have in the address bar Process.jsp, well...the url-mapping can be WHATEVER you want, you can put in the url-mapping FooFooFoo.jsp and still have the servlet Process executed, additionally, if you want your servlet to forward the request, you simply have to write inside the code of the servlet something like : RequestDispatcher view = request.getRequestDispatcher("result.jsp");

I hope this helps!
Giovanni


SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: url-mapping: Process.jsp to Process servlet