aspose file tools*
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
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: 61437
    
  67

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: 61437
    
  67

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: 61437
    
  67

Then scoped variables in request scope should do nicely.
 
Consider Paul's rocket mass heater.
 
subject: JSP String value obtained from servlet out