本文整理汇总了Java中javax.servlet.http.HttpServlet类的典型用法代码示例。如果您正苦于以下问题:Java HttpServlet类的具体用法?Java HttpServlet怎么用?Java HttpServlet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpServlet类属于javax.servlet.http包,在下文中一共展示了HttpServlet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExcludedResponseStatusCode
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Test
public void testExcludedResponseStatusCode() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
response.addHeader("ETag", "W/\"1934-1269208821000\"");
response.addDateHeader("Date", System.currentTimeMillis());
}
};
validate(servlet, null, HttpServletResponse.SC_NOT_MODIFIED);
}
示例2: testSkipBecauseExpiresIsDefined
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Test
public void testSkipBecauseExpiresIsDefined() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/xml; charset=utf-8");
response.addDateHeader("Expires", System.currentTimeMillis());
response.getWriter().print("Hello world");
}
};
validate(servlet, null);
}
示例3: init
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Override
public void init(HttpServlet servlet) throws Exception {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
ServletContext servletContext = servlet.getServletContext();
String configFileName = servletContext.getInitParameter("configFileName");
Properties properties = loadConfig(configFileName);
MybatisManager.init(properties.getProperty("config_dir"), "mybatis-config.xml", new MariadbLog());
HttpUtil.init("UTF-8", new HttpclientLog());
ThreadmsgLog threadmsgLog = new ThreadmsgLog();
AsyncThreadManager.init(100, 10, 3, 0, threadmsgLog);
AsyncThreadManager.start();
MsgManager.init(true, threadmsgLog);
CommonConfig.init(properties);
HOpCode.init();
MsgOpCode.init();
HttpManager.addFilter(new TokenHttpFilter());
HttpManager.addHttpListener(new AppService());
HttpManager.addHttpListener(new OrderRecordService());
HttpManager.addHttpListener(new PayService());
HttpManager.addHttpListener(new LoginService());
MsgManager.addMsgListener(new NotifyService(10));
}
示例4: filters
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
/**
* Add an internal servlet in the server, specifying whether or not to
* protect with Kerberos authentication.
* Note: This method is to be used for adding servlets that facilitate
* internal communication and not for user facing functionality. For
+ * servlets added using this method, filters (except internal Kerberos
* filters) are not enabled.
*
* @param name The name of the servlet (can be passed as null)
* @param pathSpec The path spec for the servlet
* @param clazz The servlet class
* @param requireAuth Require Kerberos authenticate to access servlet
*/
public void addInternalServlet(String name, String pathSpec,
Class<? extends HttpServlet> clazz, boolean requireAuth) {
ServletHolder holder = new ServletHolder(clazz);
if (name != null) {
holder.setName(name);
}
webAppContext.addServlet(holder, pathSpec);
if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
ServletHandler handler = webAppContext.getServletHandler();
FilterMapping fmap = new FilterMapping();
fmap.setPathSpec(pathSpec);
fmap.setFilterName(SPNEGO_FILTER);
fmap.setDispatches(Handler.ALL);
handler.addFilterMapping(fmap);
}
}
示例5: init
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Override
public void init(HttpServlet servlet) throws Exception {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
ServletContext servletContext = servlet.getServletContext();
String configFileName = servletContext.getInitParameter("configFileName");
Properties properties = loadConfig(configFileName);
MybatisManager.init(properties.getProperty("config_dir"), "mybatis-config.xml", new MariadbLog());
KeyLockManager.init(new UCenterKeyLockType().getkeyLockType(), 120000, 100, new KeylockLog());
HOpCodeUCenter.init();
CommonConfigUCenter.init();
CommonConfigUCenter.UCENTER_URL = properties.getProperty("uCenterUrl");
HttpManager.addFilter(new TokenHttpFilter());
HttpManager.addHttpListener(new UserService());
HttpManager.addHttpListener(new UserGroupService());
HttpManager.addHttpListener(new TokenService());
}
示例6: testEmptyContent
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
/**
* Test that a resource with empty content is also processed
*/
@Test
public void testEmptyContent() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/plain");
// no content is written in the response
}
};
validate(servlet, Integer.valueOf(7 * 60));
}
示例7: testSkipBecauseCacheControlMaxAgeIsDefined
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Test
public void testSkipBecauseCacheControlMaxAgeIsDefined() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/xml; charset=utf-8");
response.addHeader("Cache-Control", "private, max-age=232");
response.getWriter().print("Hello world");
}
};
validate(servlet, Integer.valueOf(232));
}
示例8: testUseContentTypeExpiresConfiguration
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Test
public void testUseContentTypeExpiresConfiguration() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/xml; charset=utf-8");
response.getWriter().print("Hello world");
}
};
validate(servlet, Integer.valueOf(3 * 60));
}
示例9: testUseContentTypeWithoutCharsetExpiresConfiguration
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Test
public void testUseContentTypeWithoutCharsetExpiresConfiguration()
throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/xml; charset=iso-8859-1");
response.getWriter().print("Hello world");
}
};
validate(servlet, Integer.valueOf(5 * 60));
}
示例10: testUseDefaultConfiguration1
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Test
public void testUseDefaultConfiguration1() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("image/jpeg");
response.getWriter().print("Hello world");
}
};
validate(servlet, Integer.valueOf(1 * 60));
}
示例11: testUseDefaultConfiguration2
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Test
public void testUseDefaultConfiguration2() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("image/jpeg");
response.addHeader("Cache-Control", "private");
response.getWriter().print("Hello world");
}
};
validate(servlet, Integer.valueOf(1 * 60));
}
示例12: testUseMajorTypeExpiresConfiguration
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
@Test
public void testUseMajorTypeExpiresConfiguration() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/json; charset=iso-8859-1");
response.getWriter().print("Hello world");
}
};
validate(servlet, Integer.valueOf(7 * 60));
}
示例13: setupHeadersTest
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
private void setupHeadersTest(Tomcat tomcat) {
Context ctx = tomcat.addContext("", getTemporaryDirectory()
.getAbsolutePath());
Tomcat.addServlet(ctx, "servlet", new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain; charset=ISO-8859-1");
res.getWriter().write("OK");
}
});
ctx.addServletMapping("/", "servlet");
alv = new HeaderCountLogValve();
tomcat.getHost().getPipeline().addValve(alv);
}
示例14: testContextParameters
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
public void testContextParameters() throws Exception {
WebXMLString wxs = new WebXMLString();
wxs.addServlet( "/SimpleServlet", SimpleGetServlet.class );
wxs.addContextParam( "icecream", "vanilla" );
wxs.addContextParam( "cone", "waffle" );
wxs.addContextParam( "topping", "" );
ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) );
ServletUnitClient client = sr.newClient();
assertEquals( "Context parameter 'icecream'", "vanilla", sr.getContextParameter( "icecream" ) );
InvocationContext ic = client.newInvocation( "http://localhost/SimpleServlet" );
javax.servlet.ServletContext sc = ((HttpServlet) ic.getServlet()).getServletContext();
assertNotNull( "ServletContext should not be null", sc );
assertEquals( "ServletContext.getInitParameter()", "vanilla", sc.getInitParameter( "icecream" ) );
assertEquals( "init parameter: cone", "waffle", sc.getInitParameter( "cone" ) );
assertEquals( "init parameter: topping", "", sc.getInitParameter( "topping" ) );
assertNull( "ServletContext.getInitParameter() should be null", sc.getInitParameter( "shoesize" ) );
}
示例15: filters
import javax.servlet.http.HttpServlet; //导入依赖的package包/类
/**
* Add an internal servlet in the server, specifying whether or not to
* protect with Kerberos authentication.
* Note: This method is to be used for adding servlets that facilitate
* internal communication and not for user facing functionality. For
+ * servlets added using this method, filters (except internal Kerberos
* filters) are not enabled.
*
* @param name The name of the servlet (can be passed as null)
* @param pathSpec The path spec for the servlet
* @param clazz The servlet class
* @param requireAuth Require Kerberos authenticate to access servlet
*/
public void addInternalServlet(String name, String pathSpec,
Class<? extends HttpServlet> clazz, boolean requireAuth) {
ServletHolder holder = new ServletHolder(clazz);
if (name != null) {
holder.setName(name);
}
webAppContext.addServlet(holder, pathSpec);
if(requireAuth && UserGroupInformation.isSecurityEnabled()) {
LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
ServletHandler handler = webAppContext.getServletHandler();
FilterMapping fmap = new FilterMapping();
fmap.setPathSpec(pathSpec);
fmap.setFilterName(SPNEGO_FILTER);
fmap.setDispatches(Handler.ALL);
handler.addFilterMapping(fmap);
}
}