uCosminexus Application Server, Web Service Development Guide
The javax.servlet.http.HttpServletRequest class is defined based on the Servlet 3.0 specifications.
The following example shows the usage of javax.servlet.http.HttpServletRequest that is injected into the field of a root resource class:
package com.sample.resources;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
//Root resource class
@Path("/root")
public class Resource {
//A field in which the HttpServletRequest is injected by using the Context annotation
private @Context HttpServletRequest httpRequest;
//Resource method
@GET
public String getValue() {
return this.httpRequest.getParameter("Hitachi");
}
}
|
Consider the context root of the Web application (WAR file) containing the root resource class com.sample.resources.Resource to be example, and that the Web application is published on a host named sample.com. In the above example, with the HTTP GET request corresponding to the URL http://sample.com/example/root?TestParam=TestValue, first, the javax.servlet.http.HttpServletRequest context is injected in the HttpRequest field and then the getValue() method that can process the HTTP GET request is called. Therefore, if you acquire the request parameter TestParam from the httpRequest field by using the getValue() method, the value TestValue is acquired.
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.