Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

connection.setRequestMethod("POST") inside doGet()  RSS feed

 
mi go
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



is it okay to have POST type method in doGet() ?
 
s ravi chandran
Ranch Hand
Posts: 561
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen such usage of doPost() in some projects to handle limitation of clients who are unable to communicate over doPost() directly.

But implications are the same as with doGet() in general, insecure and has limited size (256 bytes if I remember it correctly).

What are your reasons to have doPost() inside doGet()?
 
Rob Spoor
Sheriff
Posts: 21019
85
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
s ravi chandran wrote:I have seen such usage of doPost() in some projects to handle limitation of clients who are unable to communicate over doPost() directly.

But implications are the same as with doGet() in general, insecure and has limited size (256 bytes if I remember it correctly).

What are your reasons to have doPost() inside doGet()?

I think  you've misread the code. This method will perform an HTTP request to a different web application, not to the same servlet. At least I'm assuming it's a different web application, because there are easier ways to call code within the same web app.
 
mi go
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes its making call to different servlet namely WebApp1/Account who has got doPost() method. My question is that whether its normal to do or not? Or to have another servlet in WebApp1/AccountHandle that will have doGget().
 
s ravi chandran
Ranch Hand
Posts: 561
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad, did not focus on the actual call.

Should be fine I guess.

Does HttpServletResponse  sendRedirect seem to solve your requirement? 

Here is a sample from online:

Redirect would trigger an additional call and can be used to call to other web service.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66041
140
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mi go wrote:My question is that whether its normal to do or not?

Not very. Either redirect, forward, or factor the common code out into another class.
 
Did you just should on me? You should read this tiny ad:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!