473,372 Members | 1,238 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,372 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 26998
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
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.