- 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/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!