• Post Reply Bookmark Topic Watch Topic
  • New Topic

WebApp - Redirect  RSS feed

 
Vikas Grover
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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

I am using Tomcat 6.x as the container.

Thanks, Vikas
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
3. The third option would be AJAX. Let the dashboard page load up with empty divs ( you can make the UI look as it was loading like in JIRA ) and then fire up AJAX calls on page load to your servlet and use JavaScript to populate your page.

 
Vikas Grover
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saif,

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.

Thanks, Vikas
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Incorrect. You can set the "welcome file" to the URL of a servlet (assuming you are not using a really old version of a servlet container).
 
Vikas Grover
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when I browse the path of welcome-file-list, only web folder is visible, not src where Java files are stored.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java source files have nothing at all to do with the execution environment. Are you including them in your web app?

You should be compiling the Java classes and placing the class files under WEB-INF/classes.
 
Vikas Grover
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

example.png
[Thumbnail for example.png]
 
Vikas Grover
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for help. It's working now. By the use of servlet url-param in welcome-file-list does the job.

Thanks again to both of you.
 
Vikas Grover
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, I am getting a warning message from Apache Tomcat Log

WARNING: Servlet jsp is currently unavailable
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!