hi all,
i've an object (like this for example :
public class ResponseObj {
public String string1;
public String string2;
public String string3;
}
how can i send this object to the jsp ? i do have a doGet method that send some parameters to the servlet and then i need to send the ResponseObj to the jsp.
regards,
elise
-
pass an object from servlet to jsp (6 messages)
- Posted by: e d
- Posted on: April 24 2001 09:13 EDT
Threaded Messages (6)
- pass an object from servlet to jsp by Stephen Wink on April 24 2001 10:21 EDT
- pass an object from servlet to jsp by Dan Josephs on April 24 2001 10:35 EDT
- pass an object from servlet to jsp by Dan Josephs on April 24 2001 10:35 EDT
- pass an object from servlet to jsp by e d on April 24 2001 11:06 EDT
-
pass an object from servlet to jsp by Carol Enderlin on April 24 2001 04:06 EDT
- pass an object from servlet to jsp by e d on April 25 2001 07:32 EDT
-
pass an object from servlet to jsp by Carol Enderlin on April 24 2001 04:06 EDT
-
pass an object from servlet to jsp[ Go to top ]
- Posted by: Stephen Wink
- Posted on: April 24 2001 10:21 EDT
- in response to e d
Use the HttpServletRequest object in the servlet - set an attribute on the request object containing your object.
Then on the JSP simply read that attribute into an object and use.
-
pass an object from servlet to jsp[ Go to top ]
- Posted by: Dan Josephs
- Posted on: April 24 2001 10:35 EDT
- in response to Stephen Wink
You can also send it via the sesison...
RequestObj requestObj = new RequestObj();
HttpSession session = request.getSession(true);
/*
getSession with a true parameter means get me the client
session, if it doesn't exist create a new one.
*/
session.setAttribute("reqObj", requestObj);
// then forward to jsp -
pass an object from servlet to jsp[ Go to top ]
- Posted by: Dan Josephs
- Posted on: April 24 2001 10:35 EDT
- in response to Stephen Wink
You can also send it via the sesison...
RequestObj requestObj = new RequestObj();
HttpSession session = request.getSession(true);
/*
getSession with a true parameter means get me the client
session, if it doesn't exist create a new one.
*/
session.setAttribute("reqObj", requestObj);
// then forward to jsp -
pass an object from servlet to jsp[ Go to top ]
- Posted by: e d
- Posted on: April 24 2001 11:06 EDT
- in response to Stephen Wink
thanks, that's what i'm trying to use.
sorry to ask you again one more question but is the request of request.setAttribute the same one that the
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {} ?
i don't think so because i got a error like this "the method setAttributes
is not defined.
i fact my question is : why can't i do this :
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
//...... blah blah
// many code
SearchResult mySearchResult = new SearchResult();
if ( submitType.equals("apply") ) {
Myconnectionclass.updateRecord(sYear,sCurrency, myResp);
//the query that updates the record in the database
request.setAttribute("responseObj",myResp); // here is
the error
getServletContext().getRequestDispatch("/myWebApp/ConnClass2.jsp").forward(request,response);
// and here too
}
}
as I've seen in java specifications, setAttribute method is part of
javax.servlet.ServletRequest and my request here in the code is part of
javax.servlet.http.HttpServletRequest.
so what's the mess ? should i "transform" my request ? -
pass an object from servlet to jsp[ Go to top ]
- Posted by: Carol Enderlin
- Posted on: April 24 2001 16:06 EDT
- in response to e d
I got an error on the RequestDispatcher line in your code where getRequestDispatch should be getRequestDispatcher.
If request.setAttribute() doesn't work for you, I'd check the servlet version you're compiling against...setAttribute was added in Servlet 2.1.
// This code compiles OK, but wasn't written to do anything :)
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class MyTestServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
if ( true ) {
request.setAttribute("forward","false");
getServletContext().getRequestDispatcher("/myWebApp/ConnClass2.jsp").forward(request,response);
}
}
} -
pass an object from servlet to jsp[ Go to top ]
- Posted by: e d
- Posted on: April 25 2001 07:32 EDT
- in response to Carol Enderlin
okay thank you.
i've found the problem, i was using servlet API 2.1.1 and setAttribute is only sine the 2.2