Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Serializing Httpservletrequest

servlet

  • Please log in to reply
3 replies to this topic

#1 mctim

mctim

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 110 posts

Posted 12 July 2012 - 04:50 PM

I have a simple scheduling servlet that basically takes requests that he receives saves them and then returns to the sleeping state. Well after a while he should wake up and the forward the request off to some destination url. Well most of the code is fairly straight forward, but I'm really not sure how to save the params. I thought about something like this:

public void doPut(HttpServletRequest req, HttpServletResponse resp)    {
   //do work
   Map params = resp.getParameters();
   objectOutputStream.writeObject(params);
   //save that thing
}

and I'm just not sure that will work because the value of the maps are always String[] and I know I have trouble printing them. Any suggestions?
  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 12 July 2012 - 07:52 PM

There is not method named 'getParamaters' on HttpServletRequest. Perhaps you are talking about 'getParameterMap', right?
As far as I know, java.util.Map does not implement/inherits java.io.Serializable interface but I'm not sure. You can verify it. However, if it inherits/implements the Serializable interface, objectOutputStream.writeObject will work -- you know this is the only requirement to serialize any objects.
  • 0

#3 mctim

mctim

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 110 posts

Posted 12 July 2012 - 07:57 PM

I just checked. It's hash map that implements serializable. Maybe take the parameterMap and construct a HashMap w/ it?
  • 0

#4 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 12 July 2012 - 08:15 PM

It seems so that you can create a HashMap from other map. But if it does not, you can just extract the keys/values from the map provided by HttpServletRequest and add them in a newly created HashMap .
  • 0





Also tagged with one or more of these keywords: servlet

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download