我是java web服务的新手。使用jax-rs编写示例web服务时,堆栈跟踪中会出现跟踪错误。运行一个服务器,该服务器将页面加载为http状态404。为了理解,我需要编写简单的web服务,然后我必须通过android应用程序中的restful客户端访问web服务。我在这里张贴我的整个网络服务,请帮助我。
请把我引向正确的方向。提前感谢
Aug 26, 2014 6:55:04 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft\Web Platform Installer\;.
Aug 26, 2014 6:55:04 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:webService' did not find a matching property.
Aug 26, 2014 6:55:04 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Aug 26, 2014 6:55:04 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Aug 26, 2014 6:55:04 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 699 ms
Aug 26, 2014 6:55:04 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Aug 26, 2014 6:55:04 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Aug 26, 2014 6:55:06 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
webService
Aug 26, 2014 6:55:06 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class webService.myserviceClass
Aug 26, 2014 6:55:06 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Aug 26, 2014 6:55:06 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.17.1 02/28/2013 03:28 PM'
Aug 26, 2014 6:55:07 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Aug 26, 2014 6:55:07 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Aug 26, 2014 6:55:07 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2082 msweb.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>webService</display-name>
<servlet>
<servlet-name>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>webService</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Rest</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>myserviceClass.java
package webService;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// Plain old Java Object it does not extend as class or implements
// an interface
// The class registers its methods for the HTTP GET request using the @GET annotation.
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML.
// The browser requests per default the HTML MIME type.
//Sets the path to base URL + /hello
@Path("/hello")
public class myserviceClass {
// This method is called if TEXT_PLAIN is request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
} 发布于 2014-08-26 13:00:14
您必须访问的URL的格式如下:
http://your_hostname:port-number/application-context-name/rest/path-name-of-your-web-service<hostname>是localhost,因为应用程序正在您的计算机上运行。
<port-number>是8080 - tomcat服务器的默认端口。
<application-context-name>是部署在tomcat服务器中的应用程序的名称,如果您已经将它命名为webService,那么应用程序上下文名将是webService。
rest --这是在您的web.xml文件中配置的泽西Servlet的名称,按照您的xml是rest。
<path-name-of-your-web-service> --按照您的java web服务代码,这将是/hello。
所以试着:
http://localhost:8080/webService/rest/hello发布于 2014-08-26 12:07:30
我在你的猫日志里没有看到任何错误。但是,我认为您的web服务没有处理请求的servlet。(控制web.xml)或者您试图访问错误的上下文。
https://stackoverflow.com/questions/25505292
复制相似问题