HTTP 状态 405 - 不允许对 Rest API 的方法有错误
我在做了一些研究之后问了这个问题。我确实遵循了针对此类错误的解决方案,但对我不起作用。任何建议,如在下面的代码中出错的地方。我正在创建一个REST API,但是当我请求URL时,它给了我405错误。下面是请求的 URI。
http://localhost:8080/Project/services/start/version
下面是代码片段。
@Path("/start")
public class StartService {
@GET
@Path("/version")
@Produces({"text/plain","application/xml","application/json"})
public String getVersion() {
String ver="";
try{
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("C:\\server\\dgr -v" );
BufferedReader stdInput = new BufferedReader(new InputStreamReader
(pr.getInputStream()));
BufferedReader input = new BufferedReader(stdInput);
// String ver ="";
StringBuffer verOutput = new StringBuffer();
while((ver = input.readLine()) != null){
verOutput.append(ver + "\n");
System.out.println(ver);
}
}catch (Throwable t)
{
t.printStackTrace();
}
finally {
}
return ver; }
}
网页.xml:
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<display-name>eLicensingWeb</display-name>
<servlet-name>JAX-RS REST</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.cem.plc.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS REST</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>