1

I have a simple user application. I have a MainController Servlet that will be in charge of general interaction in the application. This servlet will be "listening" for url-patterns: /, /index, etc (any other form of index). I also have an UserController Servlet that is in charge of login among other things, this one "listens" from /CheckLogin url-pattern.

I have form in a jsp, in the url /, that when I submit it, it points to the servlet at /CheckLogin. Then UserController servlet process it and either the login is ok or wrong it redirect to / (the MainController will be in charge of determining the page to show depending if the user logged in or not).

All work flawlessly except that after submitting the first time, then the form page has url /CheckLogin. I would like to remove it and show only / (even if logged or not). How do I do this (plain Java EE, not Spring or any other framework)?

Bhavik Ambani
  • 6,557
  • 14
  • 55
  • 86
Christian Vielma
  • 15,263
  • 12
  • 53
  • 60

1 Answers1

2

I'm not sure if this is what you're looking for, but if you do a forward instead of a redirect, the URL on the client browser will not be updated: RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse; an explanation can be found at Forward vs Redirect.

In addition, it might be a better idea to implement authentication as a Filter instead of a Servlet; that way, the Filter can be used to intercept any URL you deem needs to be secured.

Is there a specific reason you're not using a web framework? They're meant to take care of things security and routing for you, generally.

Paul Wostenberg
  • 449
  • 2
  • 9
  • well I'm trying to learn a little bit more of java ee itself before going for a framework. I'm currently doing forward of the request. But the form has the CheckLogin pointed :S also, do you have a good link to learn a bit more about filters? – Christian Vielma Aug 03 '12 at 20:11
  • 1
    Since you are not going with Frameworks, go with patterns, they will give a good foundation before getting into frameworks: http://stackoverflow.com/questions/3541077/design-patterns-web-based-applications – davidmontoyago Aug 03 '12 at 20:36
  • 1
    More about filters: http://docs.oracle.com/javaee/6/tutorial/doc/bnagb.html This SO question talks a bit about using filters for authentication: http://stackoverflow.com/questions/4984984/authorization-using-filters-in-java-ee So are you saying that you're forwarding, but the "/CheckLogin" URL is still appearing in the browser? – Paul Wostenberg Aug 04 '12 at 15:38