java - HTTP method GET is not supported by this URL - Tomcat -


i know has been asked many times before here, after reading dozens of answers , solutions of other threads, haven't been able solve issue.

i working on computer not have administrative privileges, , best guess firewall blocks server on localhost.

here code:

gettimeservlet.java

//i have tried overriding public class gettimeservlet extends httpservlet  {      private static final long serialversionuid = 1l;      public void dopost (httpservletrequest request,httpservletresponse response)              throws servletexception, ioexception      {         stringbuilder sb = new stringbuilder();         bufferedreader reader = request.getreader();         try {             string line;             while ((line = reader.readline()) != null) {                 sb.append(line);             }         } {             reader.close();         }         response.setheader("cache-control", "no-cache");         response.setheader("pragma", "no-cache");         response.setheader("access-control-allow-origin", "*");         printwriter out = response.getwriter();         newtest.dbqueries dbq = new newtest.dbqueries();         out.print((int) math.round(dbq.getsitescore(sb.tostring())));     } } 

web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">   <display-name>exjobb</display-name>   <welcome-file-list>     <welcome-file>index.html</welcome-file>     <welcome-file>index.htm</welcome-file>     <welcome-file>index.jsp</welcome-file>     <welcome-file>default.html</welcome-file>     <welcome-file>default.htm</welcome-file>     <welcome-file>default.jsp</welcome-file>   </welcome-file-list>   <servlet>         <servlet-name>gettime</servlet-name>         <servlet-class>servlets.gettimeservlet</servlet-class>     </servlet>     <servlet-mapping>         <servlet-name>gettime</servlet-name>         <url-pattern>/get-current-time</url-pattern>     </servlet-mapping> </web-app> 

index.html

i have button runs following function onclick="ajaxasyncpostrequest('http://localhost:8080/ajaxdemo/get-current-time', $('#temp').val()):

        function ajaxasyncpostrequest(requrl, temp)         {             temp = encodeuricomponent(temp);             var params = "site=" + temp + "&userrating=" + $("#slider").val() + "&usercomment=" + $("#comment-textarea").val()             + "&chkbox1=" + $("#sq_checkbox1").val() + "&chkbox2=" + $("#sq_checkbox2").val();              //creating new xmlhttprequest object             var xmlhttp;             if (window.xmlhttprequest){                 xmlhttp = new xmlhttprequest(); //for ie7+, firefox, chrome, opera, safari             } else {                 xmlhttp = new activexobject("microsoft.xmlhttp"); //for ie6, ie5             }             //create asynchronous request             xmlhttp.open("post", requrl, true);              xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded");              //when readystate 4 server output             xmlhttp.onreadystatechange = function() {                 if (xmlhttp.readystate == 4) {                      if (xmlhttp.status == 200)                      {                         gauge.refresh(xmlhttp.responsetext);                         //alert(xmlhttp.responsetext);                     }                      else                     {                         //alert(xmlhttp.status);                     }                 }             };             xmlhttp.send(params);         } 

the form-data sent in post, , server handles post requests. i'm not getting errors or warnings either in eclipse. what's going on here?

edit: i'm trying post , not get.

for http method should define doget method in servlet (gettimeservlet.java);


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -