Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

passing Serialized objects to Servlets

  Asked By: Rani    Date: Sep 29    Category: Java    Views: 2448
  

I need to pass a serialiazed object and some parameters to my servlet. I
can pass a serialized object to my servlet, and I can pass parameters to
my servlet.
But when I try to pass both, I only get my serialized object. The other
parameter is null.
Here is the code used to pass these kind of parameters to my servlet


URL url = new
URL("http://192.168.61.77:8080/urlservlet/servlet/UrlServlet");
URLConnection connection;
connection = url.openConnection();

connection.setDoOutput(true);
// UrlSerializable is my class that implemenst Serializable
UrlSerializable urs = new UrlSerializable();
urs.setTestando("Servlet Recebendo = Objeto Serializável!!!");
// Serializing the object to the output stream that the conection
has.
OutputStream out1 = connection.getOutputStream();
ObjectOutputStream s = new ObjectOutputStream(out1);
s.writeObject(urs);

s.close();
s.flush();
// Passing paramters to the servlet. These parameters are
supossed to be fetch with the request.getParameter() method
PrintWriter outq = new PrintWriter(connection.getOutputStream());
outq.println("string=Param");
outq.close();
outq.flush();

My servlet code is:

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
try
{
Unserializing the object
ObjectInputStream s = new ObjectInputStream(in1);
UrlInterface dados = (UrlInterface) s.readObject();
dados.checaVersao();

System.out.println("***** SERIALIZABLE ****");
System.out.println("Serialized Content: "+dados.getTestando());
// here my parameter string is null. And there is content in it.
System.out.println("Param :"+req.getParameter("string"));


Any ideas ?

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on passing Serialized objects to Servlets Or get search suggestion and latest updates.




Tagged: