Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

convert String to HttpServletResponse?  RSS feed

 
mi go
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we convert normal string to HttpServletResponse or HttpServletRequest object?
 
Stephan van Hulst
Saloon Keeper
Posts: 7808
142
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. You just need to figure out what part of the request or response the string should make up. For instance, if you want the string to be in the body of the response, you can call response.getWriter(), and write the string with the writer.

Personally I find it much easier to work with frameworks that handle all of this for you though. Have you taken a look at RESTful frameworks? I find Jersey very nice to work with, and Spring MVC is also very powerful.
 
mi go
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks and how ca we use response object outside of service() methof of servlet?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't be using the service() method, you should be using one of the doGet, doPost and similar methods.

And, you should handle the response within those methods. If you feel you need to handle the response elsewhere, there is likely a flaw in your design.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!