Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher or Redirect

 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet, data from this abc.java servlet is extracted from abc.jsp. This data is worked upon and sent to xyz.jsp to display it to the client. From xyz.jsp the data is sent to a servlet to insert it into a database to store.

What should I use in abc.java? RequestDispatcher or ReDirect?? If it requestDispatcher then forward or include??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certainly not include.

Whether you forward or redirect depends upon if you want to render the JSP in the same request as the servlet (forward), or cause a new request to be generated to fetch the JSP (redirect).

The latter is most often used in the PRG pattern, and by separating server-side control into task controllers and page controllers.

More details on PRG can be found in this article.
 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, I'm new to this concept. There is one more doubt I have that is, do sendRedirect() method just sends you to the next page or It can send data from abc.java to xyz.jsp?
How do I send data from abc.java to xyz.jsp? Also I don't just wanna display it, but display it in tabular format. So, where do I do all the formatting of the data? On abc.java or xyz.jsp?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Noopur Kore wrote:do sendRedirect() method just sends you to the next page or It can send data from abc.java to xyz.jsp?

A redirect sends a response to the browser that tells it to issue another request to the redirect URL. You can "pass" data in the session, or by adding request parameters to the URL.

Redirecting to a JSP is discouraged. You should redirect to the page controller for the JSP.

How do I send data from abc.java to xyz.jsp?

During a forward, by creating scoped variable in request scope. During a redirect, see above.

Also I don't just wanna display it, but display it in tabular format. So, where do I do all the formatting of the data? On abc.java or xyz.jsp?

What do you think? Where would you place the HTML to format the table?
 
Noopur Kore
Ranch Hand
Posts: 77
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear, .
Finally All I want to know is, if I send a array or a arraylist to my xyz.jsp (containing all cell values of my excel sheet). How do I segregate this one single object into my original single cell values and display it?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can iterate over a list easily with the <:c:forEach> JSTL action. Plenty of examples are available online.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic