This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes Passing data from servlet/jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing data from servlet/jsp" Watch "Passing data from servlet/jsp" New topic
Author

Passing data from servlet/jsp

dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91
Note:
Servlet residing in, say "ServerA" I.P(121.12.12.13)
Jsp in "ServerB" I.P(131.13.13.14)

I have above scenario where I want to send some parameters/values from servlet("in ServerA") to a jsp ("in ServerB") so that jsp will process the data and return the data as a list ("java.util.list") to servlet ("in serverA").

Can some one please provide a suggestion?[
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Make a request to the remote web app using URLConnection, or HttpClient, or some other way to initiate requests under program control. Pass data as request parameters.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

dileep keely wrote:Note:
Servlet residing in, say "ServerA" I.P(121.12.12.13)
Jsp in "ServerB" I.P(131.13.13.14)

I have above scenario where I want to send some parameters/values from servlet("in ServerA") to a jsp ("in ServerB") so that jsp will process the data and return the data as a list ("java.util.list") to servlet ("in serverA").

Can some one please provide a suggestion?[


Sounds like a use case for a web service method / EJB method instead of a servlet -> JSP communication. The flow of control also seems to be in reverse

Also, since the pages / servlets are in different servers, sharing objects through some sort of scope is not possible.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
venkatesh polneedi
Greenhorn

Joined: Nov 25, 2010
Posts: 3
use the session tracking for sending values from jsp to servlet or servlet to jsp

1.hidden parameters

2.cookies

3.sessions
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91
I believe that I can do it as per the suggestion from "Bear".
Before going to test with a remote server,I started trying with the abstract class URLConnection
in different web-applications in the same server.
But,when I tried to getInputStream of a jsp from a servlet ,I get the processed data from jsp including the <html> tags.

Output:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
CTlog
</body>
</html>

How to avoid the tags from processing.?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You're going to have to parse the HTML and extract the information you need from it.

Obviously this isn't a good thing to do, but that's what you have to expect from such a design. If you want something which returns specific information then (as Deepak suggested) the design should have been some kind of web service.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

dileep keely wrote:I get the processed data from jsp including the <html> tags.

Of course. You'll get whatever the remote server returns as the response.

If you want something different, do you have control over what the remote server creates as the response? If not, can you get what you need by parsing the returned markup?

[Edit: ha! Paul beat me to the punch!]
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91
yes Bear,I do have a control over the remote server response completely(code).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Then you can modify the code to send only what you want. if you don't want HTML markup, don't send it.
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91

It means to avoid using html code tags in remote jsp is it.


Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

dileep keely wrote:Then you can modify the code to send only what you want. if you don't want HTML markup, don't send it.
It means to avoid using html code tags in remote jsp is it.


If you're not sending HTML or XML, I would avoid using JSP entirely. If you use a servlet, you can send a text/plain response that contains only your data.


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing data from servlet/jsp