This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Redirecting from JSP to Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Redirecting from JSP to Servlet" Watch "Redirecting from JSP to Servlet" New topic
Author

Redirecting from JSP to Servlet

Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi I'm new to JSP.

Can anyone please let me know how to redirect / forward JSP page to servlet without any response/input to the user.

I Mean that when user access input.jsp it should be redirected to a Servlet.

Thanks in Advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Jay Shukla wrote:I Mean that when user access input.jsp it should be redirected to a Servlet.

Since the purpose of a JSP is to present a view to the user, under what scenario would this be appropriate? It's a big red flag that you may have some serious design problems with your application.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jay Shukla
Ranch Hand

Joined: Jun 08, 2008
Posts: 214
Hi Actaully when user access my application by default it'll call index.jsp. because i don't user to access direct URI of my application so when user access my application then it'll redirected to one servlet where it'll run java code and redirect to one more jsp.

So for this purpose could you please let me know the solution for this?


Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

You can redefine what default resource they visit by setting it in the welcome-file-list of the deployment descriptor. It's doesn't have to be index.jsp -- that's just the default.

That said, you could use <jsp:forward> to forward to a new resource, or redirect in any number of ways. The most straight-forward being to use HTML META tags to specify the redirect.
 
 
subject: Redirecting from JSP to Servlet
 
Similar Threads
Scriptlets -> Time and Space Complexity
RequestDispatcher display the servlet URL, not the jsp
Do you have elegant way of nullpointer exceptions
Servlet and JSP
difference