0

Set-Up- I have a JSP - index.jsp and a servlet indexController. indexController forwards request to index.jsp. Execution of index.jsp without execution of indexController is not desired.

Requirements-

  1. 'www.mysite.com' should be served by indexController/index.jsp
  2. Any request with invalid url should get redirected to 'www.mysite.com'.
  3. 'www.mysite.com/index.jsp' should get redirected to 'www.mysite.com'.

My Solution -

  1. Map indexController to "/" - I read that this is overriding 'default servlet' and I want to avoid that.
  2. Map 'index.jsp' in welcome-file-list: I don't need to explicitly map it science 'index.jsp' is there, it will be automatically taken as welcome file. Doing this doesn't execute indexController. Moreover invalid urls are 'forwarded' not redirected to welcome file.
  3. Map error page to home page- This is cheating with yourself. I don't want to hide errors.
  4. Use two servlets. One with "/*" mapping, which redirects everything to 'mysite.com'. Second mapped to ""(empty) that actually serves request. - Some mysterious issues here(yet to figure out)

I think, everyone wants to achieve same functionality for their home screen and there are many questions at stackoverflow with similar problems.

Is there any standard solution which solves problem for once and for all.


Edit:- There were only 7 views in more than 30 mins. Removed GAE tag, to attract more views.

1 Answer 1

0

Simply put a web server before your app server and you can map any URL to any application/page. Also don't publish an app server directly. Are you using Tomcat I presume, so you probably deployed ROOT application, right? (you should go with the web server anyway)

2
  • Additionally you can make indexController a filter and not a servlet, so you can filter /* requests and you can do the redirect there. Jun 6, 2013 at 7:02
  • Thanks @Balint Bako. I was using GAE so there is no different App Server. There is only one server. I have solved this issue. I will post final solution(sort of busy for now). Jul 1, 2013 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.