• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Navigating to another page...

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I'm new to this jsp stuff. I have a page (Page1) that uses another page (Page2) to submit some data to a database. When Page2 is done processing, I want the browser to navigate back to Page1.
I tried using the following, but the text in the 'Address' box at the top of my browser is reflecting the URL for Page2...
<jsp:forward page="Page1.jsp" />

Is there just a quick and easy way to fix this?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're doing processing only (no display) you'd usually use a servlet rather than a JSP, but to answer the actual question...
Have a look at the sendRedirect method on the response object.
Dave.
 
curtis harrison
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok,
Again, I'm new to this stuff... What's a servlet? How do you implement it? Pretend I'm REALLY new. Spoonfeeding is appreciated.
Could you give me an example of EXACTLY how to use the sendRedirect() statement works? (ie: Arguements? Where I get the HTTP Path, if needed...)
Thanks,
Curtis
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My perspective on the servlet/JSP thing:

A servlet is a java class that provides 'extended behaviour' for a web server. It's like the cgi programs people used to write (and still do) in C or Perl. Among many other uses, servlets can be used to process form submissions on websites, generate 'plain HTML' pages (with dynamic content) or in the JSP world, they are sometimes used as a 'controller'.

Before JSP, if you wanted dynamic data in a HTML page, you'd need to write a servlet that contained a whole bunch of 'out.println()' statements that would print out the HTML tags required. But with JSP, you can instead, write the HTML plainly, and embed the Java code between <% %> tags for the dynamic data. JSP's are then compiled into a servlet for you, and in fact, you should write a simple Hello world JSP, and view the java source file for the generated servlet. It really helped me get a grip on how JSP works. I'd also highly recommend the book "Professional JSP 2nd Edition" by WROX.

In your example, (page 2 that has no output), it makes sense to write this as a servlet, as JSP is primarily meant to make the process of writing dynamic pages easier. But all you really need is a form processor, so a servlet makes more sense. The action target of the form would be the servlet's aliased name.

However, if you don't want to get into writing servlets and fooling around with aliases, writing a JSP that is nothing but Java code between <% %> tags, is an acceptable solution for now.

Finally, sendRedirect() is the solution you'd want, because it literally sends the browser a redirect command.. sort of like if you go to pages that say "you will be automatically redirected, click here if you aren't"

When the browser performs the redirect, it replaces the address bar's URL with the URL to which it is redirecting. So it 'looks' right as well as working right.

I haven't used redirect in a JSP page, but within the code of a servlet, it looks like:
 
Does this tiny ad smell okay to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic