我有使用球衣的Webservice。我想訪問一個從rest服務創建的servlet中的hashmap。在應用程序啓動過程中,servlet sholud中的hashmap只能創建一次。 這是web.xml中如何使用Jersey從其他Web服務中使用Servlet
<?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>GrpService_Map</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>jersey-serlvet</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.ericsson.mapService</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
服務類TestService的是com.ericsson.mapService包內。我的問題是我在那裏將放置所需的servlet創建的HashMap和我將如何訪問從TestService的地圖? 這是我的服務類TestService.java
@Path("/Service")
public class TestService {
@GET
@Consumes("application/xml")
@Produces(MediaType.TEXT_PLAIN)
@Path("/cacheserviceTestMap")
public String createGroupCache(@Context HttpServletRequest request)
throws IOException {
//here i want to access the IndexMap hashmap
return "Success";
}
}
這是我的servlet類
public class TestSerlvet extends HttpServlet{
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
Map<String, Map<String,List<String>>> IndexMap = new HashMap<String, Map<String,List<String>>>();
Map<String,List<String>> signumMap = new HashMap<String,List<String>>();
List<String> grp = new ArrayList<String>();
grp.add("1");
grp.add("2");
signumMap.put("eab", grp);
signumMap.put("eabc",grp);
signumMap.put("exy",grp);
IndexMap.put("I", signumMap);
}
}
謝謝
請發佈'TestService.java',你的servlet和服務代碼中失敗或嘗試訪問servlet'HashMap'的地方。 –
發佈服務類和servlet,並從我想要訪問的hashmap –