I am creating a webapp and I have one issue which I am explaining below.
When mysite.com is opened, it is supposed to show news, events information and other information on homepage, Like a news website. Now to retrieve that info I have a servlet which calls other classes for this information and then return it back while responding. This all is working, but through a response.sendRedirct command from index.jsp file. That file is doing a redirect to call the servlet and then it sends the information to a new page.
Since its a redirect its not good for performance. How can it be avoided and still all information can be shown when site is opened.
User types mysite.com --> On Server there is index.jsp ---> Which redirects to servlet to retrieve information --> Servlet gather the info and through dispatcher send it to new jsp page
Greetings Vikas and welcome to the ranch
I can think of 3 possible solutions to your situations ( there can be more ) .
1. First would be to make your URL hits the servlet first and then your JSP is displayed. Like this user enters mysite.com --> map your servlet in the deployment descriptor . this way your servlet will get called first and then your JSP will be rendered.
2. The second option would be to have a re-direction on your tomcat so that any URL on mysite.com is automatically redirected to another URL ( e.g our servlet URL mysite.com/yourservlet ) . Take a look at HttpRedirectFilter.
Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Thanks a lot for the prompt reply. Really appreciate that.
I actually liked the first option and thats the one I always wanted to do. Let Servlet takes care of request first before the home page is displayed.The other options have some drawbacks, like redirection and use of AJAX.
Can you advise me how can I achieve option 1? <welcome-file-list> only takes jsp/html not .java files.
Yes, the class files are there and in build folder they can be seen. I am attaching an image of the current webapp, which explains what's happening? Let me know if it makes any sense. Many thanks for the help.