• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can we change default method from GET to POST

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you try in this way?
---------------
doGet(){

doPost();


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

Like doGet() method inturn calling doPost() observe if long URL works
 
Greenhorn
Posts: 23
Firefox Browser Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your url is such big then why don't you pass the parameters in HttpServletRequest variables setParameter() method...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no such method as setParameter. ikf you meant setAttribute, that's not applicable in this case.
reply
    Bookmark Topic Watch Topic
  • New Topic