I would like to know if it's possible to pass object pointers in servlet
requests. I want a servlet to pass an object pointer into an HTTP response,
and
then another servlet to get the object pointer from an HTTP request.
Example (pseudo)code:
class Hello
{
private String name;
public Hello(String n)
{
name=n;
}
public void hello()
{
System.out.println("Hello, "+name+"!");
}
}
class Servlet1 extends javax.servlet.HttpServlet
{
// standard servlet stuff...
public void doGet(HttpRequest request, HttpResponse response) throws
IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
response.setObject("hello",new Hello("world"));
// ^ This is what I'd like to know is possible or not? This (imaginary)
// method sets an HTTP header, parameter, whatever, named "hello" to a
// pointer (reference) to a Hello object.
out.println("<html><title>Sample page</title>");
out.println("<body>Click <a
href=\"http://my.host:8080/servlet/Servlet2\">");
out.println("here!</a></body></html>");
out.close();
}
}
class Servlet2 extends javax.servlet.HttpServlet
{
// standard servlet stuff...
public void doGet(HttpRequest request, HttpResponse response) throws
IOException, ServletException
{
response.setContentType("text/plain");
PrintWriter out=response.getWriter();
out.println("It worked!");
out.close();
Hello myhello=(Hello)request.getObject("hello");
// ^ This is another (imaginary) method. It gets the object pointer
// (reference) from an HTTP header, parameter, or something.
myhello.hello();
}
}
This would then work this way: I call my first servlet (Servlet1) from a web
browser. Servlet1 generates a Hello object with the name field containing
"world". The output in the browser contains a link to Servlet2. When I click
on the link, the browser call Servlet2, which outputs "It worked!" into the
browser, gets the reference to the Hello object, and prints out
"Hello, world!" to the console where servletrunner is running.
Is this possible in any way? If so, it would help me a great deal with the
application I'm supposed to be developing. Thanks a lot for any help!
Joona Palaste
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html