我在 Linux 发行版(Raspbian、Tomcat 7)上运行我的代码时遇到问题。在Windows/Tomcat 7/Eclipse下的测试环境中没有出现问题:
我的网络服务只返回 HTTP 204 而没有别的。该日志不包含任何指示请求期间出现错误的指示。就像在测试环境中所做的那样,它应该以 json 响应。
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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
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>***</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>
<listener>
<listener-class>**.useravailability.UserAvailabilityServletContextListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>REST Service</servlet-name>
<url-pattern>/REST/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>REST Service</servlet-name>
<servlet-class>com.sun.jersey.server.impl.container.servlet.ServletAdaptor</servlet-class>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
用户服务.xml
package **.webservice;
import java.util.ArrayList;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import com.google.gson.Gson;
import **.model.AccessManager;
@Path("/usersService")
public class UsersService {
@GET
@Produces("application/json")
public String getUser() {
String user = null;
ArrayList<String> userList = new ArrayList<String>();
try {
userList = new AccessManager().getUser();
Gson gson = new Gson();
user = gson.toJson(userList);
} catch (Exception e) {
e.printStackTrace();
}
return user;
}
}
我错过了什么?为什么它可以在测试环境中工作?谢谢!