473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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");
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
8 26989
JosAH
11,448 Expert 8TB
@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
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
JosAH
11,448 Expert 8TB
@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
change your code like that...
RequestDispatcher dispatcher = request.getRequestDispatcher("/test.jsp");
dispatcher.forward(request,response);

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
dmjpro
2,476 2GB
@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
jayesh
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

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

Similar topics

1
by: K S Aldebaraan | last post by:
I'm trying to submit a form with an action of a servlet, and a view equal to the same jsp page. I'm not sure what I'm doing wrong, but keep getting a NullPointerException on the second line of...
1
by: Vasil Slavov | last post by:
I apologize for the long email. I hope somebody will have time to read it and give some suggestions. I am working on a school project written in Python (using mod_python) and I need to upload a...
3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
1
by: sang | last post by:
Hi I prepared a program for Email Integration. That is email send to others through servlet's. I gave the code but it has some error in my code. Please check the code and give the feedback. ...
6
by: santhoskumara | last post by:
How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am...
14
by: ramadeviirrigireddy | last post by:
Hi All, I have the following code for form and servlet. when the form is submitted the servlet will print the values passed by the form. i'm not getting the servlet o/p when i submit the...
7
evilmonkey
by: evilmonkey | last post by:
My assignment was to create a shopping cart servlet, it works locally on tomcat but when I deploy it to the schools server (also tomcat) it fails to refresh the front page and just prints the HTML...
0
by: krishna81m | last post by:
Could some one please explain why the session is not being maintained when I am doing a forward in a servlet after setting a cookie. I am even unable to set session attributes or parameters and...
3
by: vijaykumardahiya | last post by:
Dear Sir, I have two queries. First question is: I have a Html page. On which Have two buttons Submit and Issue. I want when I click on Sumit button request should be go to submit.jsp. and When I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.