471,854 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,854 software developers and data experts.

JSP/Servlet - Request Dispatcher

I'm design MVC structure for current developing system.
Initially, the jsp will post data to servlet class. After processing, servlet will use the requestDispatcher to return processed data back to jsp.

RequestDispatcher dispatcher = request.getRequestDispatcher("/webapps/hrd/test.jsp");

Now, the process the successful but i found the url display on address bar still remain as servlet url. It cannot change to the jsp url. who's know how to change it, if we don't use session?

Cause, i though MVC suppose separate the java code from the jsp, let jsp for display purpose and servlet for business process logic. Is the servlet can send data to jsp webpage?
Apr 2 '09 #1
8 26809
11,448 Expert 8TB
The Dispatcher.forward( ... ) never reaches the client; as far as the client is concerned it receives a response from the URL it sent to the server. That's why the URL display on your client doesn't change.

Yep, keep the functionality separated: JSPs for display purposes and Servlets (and beans called from it) for the control logic and business logic. The Servlet can send data to the JSP through the request/response objects.

kind regards,

Apr 2 '09 #2
Hi, thank for you rapidly response.

In my case, the servlet use dispatcher.forward method to send REQUEST object to jsp and receive HTML output from jsp. It is didn't move to jsp but just receive and display the HTML code from jsp. Is it what's you mean?

In this case, how you design the servlet send back data to jsp. What's method are you applying?
Apr 3 '09 #3
OK, finally i still need store data into session in order to transfer from servlet to jsp.
Who has experience the javabean before. Can it list down a list of table instead of single object?
Apr 9 '09 #4
11,448 Expert 8TB
You can put any Java object in the request/response/session object you want. That includes Maps, Lists, Tables etc.

kind regards,

Apr 9 '09 #5
change your code like that...
RequestDispatcher dispatcher = request.getRequestDispatcher("/test.jsp");

I think it will work...
Apr 28 '09 #6
thk for reply. The code is not problem to execute.
I jz want to know how to change the url address after dispatcher has been execute.
If you have any idea about it?
Apr 29 '09 #7
2,476 2GB
What you want that's not possible using Dispatcher as Josh mentioned, request does not reach the client after Dispatcher.forward. If you want to show the URL then use response.sendRedirect but you have to start MVC from the beginning.
Why do you want to show the URL? As the developers try to hide the exact URI from the user... ;)
Apr 29 '09 #8
Hi webster5u,

the request dispatcher is used to hide the url for that page which you dispatch and thats is a secure way, thats no one can finr your page link,

but if you want to show the url in address bar then you can use response.sendRiderct("xyz.jsp") this method.

and for storing data, i dont know javabeans but you can store data in session using session.setAttribute("paarameter","value") this method.

let me know if you have any doubt.
Nov 16 '11 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Vasil Slavov | last post: by
7 posts views Thread by evilmonkey | last post: by
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.