Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we change default method from GET to POST

 
Ram Chhabra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having one URL as below and having one corresponding servlet to that as Java Class.

URL: http://localhost:8080/myapp/test

My Code is working fine but by default the GET method is being called in my Servlet.

I dont want to call the doGet() method by default, i want to call do Post(), can i do that and i am not using any JSP page, i am directly pasting the above URL in browser and pressing enter

Thanks,
Ram
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. If you type in an URL in the browser, then the browser will send an HTTP GET request. There is no way you can change the behaviour of the browser so that it sends a POST request when you type in an address in the address bar.

What is the reason why you would want that?
 
Ram Chhabra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.

I just want because my URL is more then allowed limit for GET i.e. 1024 bytes.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have such an incredibly long URL?

You could make a new page with a much shorter URL, put a form on that page with method="POST", and then add some JavaScript to automatically post the form to the page that you want to get to.
 
aleem khan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you try in this way?
---------------
doGet(){

doPost();


}
----------------

Like doGet() method inturn calling doPost() observe if long URL works
 
kishukishor patil
Greenhorn
Posts: 23
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your url is such big then why don't you pass the parameters in HttpServletRequest variables setParameter() method...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such method as setParameter. ikf you meant setAttribute, that's not applicable in this case.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic