当前位置: 首页>>代码示例>>Java>>正文


Java HttpServlet类代码示例

本文整理汇总了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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:18,代码来源:TestExpiresFilter.java

示例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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:18,代码来源:TestExpiresFilter.java

示例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));
}
 
开发者ID:dianbaer,项目名称:epay,代码行数:24,代码来源:Expand.java

示例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);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:32,代码来源:HttpServer2.java

示例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());
}
 
开发者ID:dianbaer,项目名称:startpoint,代码行数:17,代码来源:Expand.java

示例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));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:20,代码来源:TestExpiresFilter.java

示例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));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:18,代码来源:TestExpiresFilter.java

示例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));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:TestExpiresFilter.java

示例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));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:18,代码来源:TestExpiresFilter.java

示例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));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:TestExpiresFilter.java

示例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));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:TestExpiresFilter.java

示例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));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:TestExpiresFilter.java

示例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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:TestMimeHeaders.java

示例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" ) );

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:21,代码来源:WebXMLTest.java

示例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);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:HttpServer.java


注:本文中的javax.servlet.http.HttpServlet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。