This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP String value obtained from servlet out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP String value obtained from servlet out" Watch "JSP String value obtained from servlet out" New topic
Author

JSP String value obtained from servlet out

g forte
Greenhorn

Joined: Aug 28, 2003
Posts: 25
Pseudo code:

//Servlet
String theString = "Servlet's output String";
PrintWriter out = response.getWriter();
out.print(theString);


//JSP
<%
String thestringFromServlet = Servlet's output String;
%>





Is this possible?
TIA!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Assuming that you are getting to the JSP from the servlet via a forward, no. What is it that you're really trying to do? And is the assumption about the forward correct?

There are ways to get data from the servlet to the JSP, but the response buffer is not one of them.
[ March 14, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
g forte
Greenhorn

Joined: Aug 28, 2003
Posts: 25
Bear,
thanks for the reply.
I am using the NTLM servlet to pull the authenticated username from the browser.
So for instance if I access the Servlet it prints out mydomain/gforte.
I was trying to "include" the Servlet in my jsp and "grab" that string(mydomain/gforte).

I could easily do this by accessing the Servlet first and then redirect to my jsp and pass this as a POST parameter OR set a session in the servlet and then redirect, but I was trying to keep it modular so that other apps could use it.

How else could I access a Variable called authenticatedUser (that resides in the Servlet) from my jsp without a redirect from the servlet?

Thanks for any tips!
[ March 14, 2007: Message edited by: g forte ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Again that all depends upon the relationship berween the serlvet and the JSP.

Included? Forwarded? Redirected?
g forte
Greenhorn

Joined: Aug 28, 2003
Posts: 25
Sorry, Included.
Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Then scoped variables in request scope should do nicely.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP String value obtained from servlet out
 
Similar Threads
Getting JSP's HTML output inside the same JSP
�JavaScript to Java and back again� A developers adventure
Saving word document in browser doesn't work
Can you return a local variable value from a function in Java?
Default value in RT Exp formater