• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet mapping asterisk and forwarding to jsp

 
Luis Villa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have a servlet with mapping * (to serve all requests in the application). After executing come code, I want to render a JSP, but when I apply the code:



an infinite loop is provocked (as the servlet is used also to serve the jsp because of the mapping). Is there any way to avoid this problem? The effect I want is to pass through the servlet in any request, and then serve a jsp, an image, a file, etc.

Should I use a Filter or can I keep on using a servlet?

Thank you all in advance!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luis Villa wrote:I have a servlet with mapping * (to serve all requests in the application).

As you have seen that's a very very bad idea. It means all requests for everything go to the servlet, which is, of course, not what you really want.

If you want code to run on every request prior (or after) the addressed resource runs, that's what a filter is for.
 
Luis Villa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Luis Villa wrote:I have a servlet with mapping * (to serve all requests in the application).

As you have seen that's a very very bad idea. It means all requests for everything go to the servlet, which is, of course, not what you really want.

If you want code to run on every request prior (or after) the addressed resource runs, that's what a filter is for.


Yes, I was expecting that. I'll change my code to implement the logic on a Filter instead of a Servlet.

Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.

And welcome to the Ranch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!