• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

url-mapping: Process.jsp to Process servlet

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic