- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试用 Java 设置 REST 服务的新手。我创建了一个简单的java程序并将war文件部署在apache-tomcat-8.5.5中(在apache-tomcat-8.5.5\webapps目录下)。但是当我尝试访问 REST 服务 ( http://localhost:8081/SampleRS/rest/sampproj/uservalue ) 时,收到 404 错误。(在8081端口启动tomcat{本来想做一个 POST - 使用 Postman,但出现错误,然后添加了 GET 方法来验证,但仍然出现错误)
Java 文件:
package sampproj;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.PathParam;
@Path("sampproj")
public class WSPostSer {
public WSPostSer() {
super();
}
@POST
@Consumes("application/json")
@Path("devpost")
public String createTemp (String devName){
System.out.println (" in reate");
return "heloo" + devName;
}
@GET
@Produces("text/plain")
@Path("/uservalue")
public String welcomeResource (@PathParam("uservalue") String username){
System.out.println(" welcomeResource ");
return "heloo Get " + username;
}
}
网络 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"
id="WebApp_ID" version="3.0">
<display-name>SampleRS</display-name>
<servlet>
<servlet-name>Jersey RESTful Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>sampproj</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
lib(jar)是:
Log file localhost_access_log.2016-09-10: 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:16:56 +0530] "POST /SampleRS/rest/sampproj/devpost HTTP/1.1" 404 1052 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:18:46 +0530] "POST /SampleRS/rest/sampproj/devpost HTTP/1.1" 404 1052 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:24:57 +0530] "GET /SampleRS/rest/sampproj/uservalue HTTP/1.1" 404 1056 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:25:04 +0530] "GET /SampleRS/rest/sampproj/hell HTTP/1.1" 404 1046 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:25 +0530] "GET / HTTP/1.1" 200 11450 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:26 +0530] "GET /tomcat.css HTTP/1.1" 200 5926 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:26 +0530] "GET /tomcat.png HTTP/1.1" 200 5103 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:26 +0530] "GET /favicon.ico HTTP/1.1" 200 21630 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /bg-nav.png HTTP/1.1" 200 1401 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /asf-logo.png HTTP/1.1" 200 17811 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /bg-upper.png HTTP/1.1" 200 3103 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /bg-button.png HTTP/1.1" 200 713 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /bg-middle.png HTTP/1.1" 200 1918 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:42 +0530] "GET /SampleRS HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:30:02 +0530] "GET /SampleRS HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:15:49:20 +0530] "GET /SampleRS/rest/sampproj/uservalue HTTP/1.1" 404 1056 0:0:0:0:0:0:0:1 - - [10/Sep/2016:15:49:20 +0530] "GET /favicon.ico HTTP/1.1" 200 21630 0:0:0:0:0:0:0:1 - - [10/Sep/2016:16:07:42 +0530] "GET /SampleRS/rest/sampproj/uservalue/df HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:16:07:49 +0530] "GET /SampleRS/rest/sampproj/uservalue=df HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:16:22:41 +0530] "GET /SampleRS/rest/sampproj/user HTTP/1.1" 404 1046 0:0:0:0:0:0:0:1 - - [10/Sep/2016:17:40:07 +0530] "GET /SampleRS/rest/sampproj/uservalue/me HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:17:43:08 +0530] "GET /SampleRS/rest/sampproj/uservalue/me HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:04:23 +0530] "GET /SampleRS/rest/sampproj/uservalue/me HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:04:31 +0530] "GET /WSwebapp/SampleRS/rest/sampproj/uservalue/me HTTP/1.1" 404 1080 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:04:40 +0530] "GET /WSwebapp/rest/sampproj/uservalue/me HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:09:10 +0530] "GET /WSwebapp/rest/sampproj/uservalue/me HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:20:25 +0530] "GET /WSwebapp/rest/sampproj/uservalue/me HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:21:04 +0530] "GET /WSwebapp/rest/sampproj/uservalue/me HTTP/1.1" 404 1008
catalina.2016-09-10: 10-Sep-2016 17:45:33.158 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\apache-tomcat-8.5.5\webapps\WSwebapp.war has finished in 2,632 ms 10-Sep-2016 17:45:33.235 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8081"] 10-Sep-2016 17:45:33.248 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"] 10-Sep-2016 17:45:33.259 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8081"] 10-Sep-2016 17:45:33.267 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"] 10-Sep-2016 17:57:11.249 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.5 10-Sep-2016 17:57:11.253 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:
Aug 31 2016 19:51:16 UTC 10-Sep-2016 17:57:11.253 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:
8.5.5.0 10-Sep-2016 17:57:11.254 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:
Windows 7 10-Sep-2016 17:57:11.254 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:
6.1 10-Sep-2016 17:57:11.255 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:
amd64 10-Sep-2016 17:57:11.255 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:
C:\Program Files\Java\jdk1.8.0_91\jre 10-Sep-2016 17:57:11.256 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_91-b15 10-Sep-2016 17:57:11.256 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:
Oracle Corporation 10-Sep-2016 17:57:11.256 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:
C:\apache-tomcat-8.5.5 10-Sep-2016 17:57:11.257 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:
C:\apache-tomcat-8.5.5 10-Sep-2016 17:57:11.260 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 10-Sep-2016 17:57:11.262 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\apache-tomcat-8.5.5\conf\logging.properties 10-Sep-2016 17:57:11.264 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 10-Sep-2016 17:57:11.268 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\apache-tomcat-8.5.5 10-Sep-2016 17:57:11.273 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\apache-tomcat-8.5.5 10-Sep-2016 17:57:11.278 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\apache-tomcat-8.5.5\temp 10-Sep-2016 17:57:11.283 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent 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\jdk1.8.0_91\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:\oraclexe\app\oracle\product\11.2.0\server\bin;;C:\Program Files\Broadcom\Broadcom 802.11;;;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files\Java\jdk1.8.0_91\bin;. 10-Sep-2016 17:57:11.634 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8081"] 10-Sep-2016 17:57:11.950 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 10-Sep-2016 17:57:11.957 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"] 10-Sep-2016 17:57:11.983 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 10-Sep-2016 17:57:11.985 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1694 ms 10-Sep-2016 17:57:12.061 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina 10-Sep-2016 17:57:12.065 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.5 10-Sep-2016 17:57:12.135 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\apache-tomcat-8.5.5\webapps\WSwebapp.war 10-Sep-2016 17:57:15.713 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 10-Sep-2016 17:57:16.210 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [305] milliseconds. 10-Sep-2016 17:57:16.264 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\apache-tomcat-8.5.5\webapps\WSwebapp.war has finished in 4,128 ms 10-Sep-2016 17:57:16.267 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\docs 10-Sep-2016 17:57:16.324 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\docs has finished in 58 ms 10-Sep-2016 17:57:16.325 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\examples 10-Sep-2016 17:57:17.600 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\examples has finished in 1,275 ms 10-Sep-2016 17:57:17.601 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\host-manager 10-Sep-2016 17:57:17.687 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\host-manager has finished in 86 ms 10-Sep-2016 17:57:17.688 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\manager 10-Sep-2016 17:57:17.761 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\manager has finished in 74 ms 10-Sep-2016 17:57:17.762 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\ROOT 10-Sep-2016 17:57:20.655 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 10-Sep-2016 17:57:20.766 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\ROOT has finished in 3,004 ms 10-Sep-2016 17:57:20.777 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8081] 10-Sep-2016 17:57:20.828 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009] 10-Sep-2016 17:57:20.864 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 8874 ms
最佳答案
将方法更改为:
@GET
@Produces("text/plain")
@Path("{uservalue}")
public String welcomeResource (@PathParam("uservalue") String username){
System.out.println(" welcomeResource ");
return "heloo Get " + username;
}
您的 war 文件名为 WSwebapp.war,因此请在浏览器中输入以下 URL:
http://localhost:8081/WSwebapp/rest/sampproj/me
你应该会看到heloo Get me
:)
关于java - 初学者Java REST 404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39425357/
我不明白为什么我会从 GHCi 得到以下回复。不是Maybe构造函数? Prelude> :t Maybe :1:1: Not in scope: data constructor `Maybe' P
场景是我在此网站上有不同的访问级别,我有一个适用于所有有效用户的简单登录流程,但是我现在尝试分隔不同的用户以实现对页面的不同访问。 这是我页面开头的代码: // CHECKS IF THE USER
我的任务是:写下数字1-100。如果该数字可以被 3 整除,则将其写入数字“它可以被 3 整除”旁边的控制台。如果数字是 5,也将其写入数字旁边的控制台“它可以被 5 整除”,如果它不能被 3 整除,
我有一堆实现协议(protocol) P 的记录 (A B C)。 我想编写一个方法,该方法将选择一种记录类型,构造它,然后调用它的方法。 例如,如果我有一个记录列表(def types '(A B
我的任务是编写一个程序,根据以下三个因素来预测您的年度燃料使用量汽车加油。我必须使用两个单独的类。这是我的第一个类,名为 AnnualFuelUse。 public class AnnualFuelU
我是 JavaScript 新手。我已经通过 Learning JavaScript (o'reilly) 完成了我的工作,但我只是想制作我的第一个 JavaScript。 我认为最好从事我感兴趣的事
我真的刚刚开始学习如何用 Python 编写代码。我有兴趣 如何重现 u[x,t] 矩阵。我尝试了 return u,它抛出了一个错误。 如果此代码中 for 循环的位置正确并正常运行。 最重要的是,
我不明白 view("") 在作为 Model 对象一部分的以下 javascript 方法中的作用: addView: function(view) { this.views
所以我正在尝试将 AppKit 导入到我的 python 项目中。我正在使用 pyCharm,但每次我尝试导入时,都会收到以下错误消息: You are using pip version 6.0.8
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 2 年前。 Improve
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
好吧,不知道在哪里问这个,但我是一个初学者程序员,使用 Perl。我需要创建一个数组数组,但我不确定使用数组/哈希引用、哈希数组或数组哈希等是否更好。 我需要一组匹配项:@totalmatches 每
我最近开始学习 PHP。我做了一个基本的网站,基本上想给它密码。如果有人能告诉我为什么这不起作用,我将不胜感激。我知道它不起作用,因为我已经尝试过了;我只是不明白为什么。 ... REST OF W
我试图理解 C 中的整个指针和取消引用。我几乎明白了,但遇到了非常简单的代码,结果我不明白: char *ptr = "Characters"; char val = *ptr; char *chrp
首先,我有这个列表(在练习中建议): Members = [('Tessa','G1'),('Evan','G2'),('Tom','G3'), ('Mia','G3'),('Claire','G3'
我有以下列表: listofanimals = ['Dog', 'Cat', 'Frog', 'Tiger', 'Sheep', 'Lion'] 我想根据字典对这个列表进行排序: score_card
1 userID = floatval($userID); 13 } else { 14 $this->userID = floatval(
我是 R 新手,遇到了一段我不理解的代码。更具体地说,我想知道 .Internal做。这是我尝试转换为 Matlab 的示例: dunif 我想知道.Internal和 做。 非常感谢您, 西蒙 最
我是一名优秀的程序员,十分优秀!