By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 2,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

JSP/Servlet - Request Dispatcher

P: 28
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");
dispatcher.forward(request,response);

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
Share this Question
Share on Google+
8 Replies


Expert 10K+
P: 11,448
@webster5u
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,

Jos
Apr 2 '09 #2

P: 28
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

P: 28
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

Expert 10K+
P: 11,448
@webster5u
You can put any Java object in the request/response/session object you want. That includes Maps, Lists, Tables etc.

kind regards,

Jos
Apr 9 '09 #5

P: 20
change your code like that...
RequestDispatcher dispatcher = request.getRequestDispatcher("/test.jsp");
dispatcher.forward(request,response);

I think it will work...
Apr 28 '09 #6

P: 28
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

dmjpro
100+
P: 2,476
@webster5u
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

P: 1
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.