• 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

Trying to access a servlet on button click

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am trying to call a servlet on button click.Its not a submit button,but a graphical button (not a part of form).
When i click the button get the message:

HTTP STATUS 405:HTTP method GET is not supported by this URL.
The specified HTTP method is not allowed for the requested resource.

When i reference a jsp page it displays the page.Is there any way that I can call a SERVLET and send some information along the servlet name.If yes ,what should be the code?

Thanks.
 
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
As this is about servlets, it has been moved to the Servlets forum.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Originally posted by Ghazala Islam :
Is there any way that I can call a SERVLET and send some information along the servlet name.If yes ,what should be the code?




I am afraid you cannot do that with servlets. Servlets only process the requests through the service() or doGet() or doPost() methods. You have to use a form with one of these methods to access the service methods. Clicking a graphical button without a from cannot take you to a servlet. There is no other way. Lets say if even if you send parameters in the URL, how will you invoke the service methods? You got to re-adjust your application.

 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What method did you override....

doget or dopost??
 
Bear Bibeault
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

Originally posted by rao raghu:
Clicking a graphical button without a from cannot take you to a servlet.



Horse pockey! There are numerous ways this could be accomplished via Javascript.
 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet is overriding dopost method.
 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet is overriding dopost method.
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
implement doget method.. and pass all the data you want to use in servlet in querystring.. for e.g.
http://url/servlet/MainServlet?userId=Ali&password=Ali

in doget method of servlet...get values of parameter via request.getParameter("userId")
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ghazala Islam:


HTTP STATUS 405:HTTP method GET is not supported by this URL.
The specified HTTP method is not allowed for the requested resource.



Most probably you did not implement the doGet() method.
Try doing that first and tell us how it goes.
 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is pretty much solved as i had not override the doGet method in the servlet.
One more question,how can i associate a dyanamic value with a url,as usually we append fixed value with url as below,

http://url/servlet/myservlet?companyid=xyz
but what if company id changes everytime?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic