• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling doPost from response.sendRedirect

 
Pradhip Prakash
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi All,

Can we make a call to doPost of a servlet directly via response.sendRedirect.

If yes, please tell me how.

Thanks,

Prad
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can't . sendRedirect generate new request/response and it goes to doGet method . you may call doPost from there .
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and it goes to doGet method . you may call doPost from there .

But you shouldn't. The HTTP spec is quite clear on the fact that GET and POST are to be used for different things. A web app that uses them interchangeably is semantically broken.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to achieve that would be to send an actual response (rather than a redirect) which on page load, submits a form using a post request.

ram.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
But you shouldn't. The HTTP spec is quite clear on the fact that GET and POST are to be used for different things. A web app that uses them interchangeably is semantically broken.

Agree.
 
Jagdishkumar Patel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradhip Prakash wrote:
Hi All,

Can we make a call to doPost of a servlet directly via response.sendRedirect.

If yes, please tell me how.

Thanks,

Prad


You are on the wrong way, instead of sendredirect use HTTP Client and make Post Connection
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are on the wrong way, instead of sendredirect use HTTP Client and make Post Connection

This won't work, since it's a browser making the request, not a Java client.
 
Jagdishkumar Patel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
You are on the wrong way, instead of sendredirect use HTTP Client and make Post Connection

This won't work, since it's a browser making the request, not a Java client.


you can make a connection from first servlet, from where you are doing redirect, instead of redirect make a http connection to second servlet.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can make a connection from first servlet, from where you are doing redirect, instead of redirect make a http connection to second servlet.

The redirect takes the request back to the browser, so that's where the request would be coming from. It's moot to speculate on what other designs are possible if this requirement is relaxed; maybe Pradhip Prakash can clarify what is actually intended.
 
Sumukh Deshpande
Ranch Hand
Posts: 87
Firefox Browser IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you shouldn't. The HTTP spec is quite clear on the fact that GET and POST are to be used for different things. A web app that uses them interchangeably is semantically broken.


"Seetharaman Venkatasamy" Where should I get details about this? Should I read a RFC for that?
 
Prabhat Shankar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can call doPost or doGet method from form submission.
At the time of form submission you can set the method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!