本文整理汇总了Java中org.apache.jasper.servlet.JspServlet类的典型用法代码示例。如果您正苦于以下问题:Java JspServlet类的具体用法?Java JspServlet怎么用?Java JspServlet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JspServlet类属于org.apache.jasper.servlet包,在下文中一共展示了JspServlet类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpHttpServer
import org.apache.jasper.servlet.JspServlet; //导入依赖的package包/类
private void setUpHttpServer() throws Exception {
server = new HttpServer();
SocketListener listener = new SocketListener();
listener.setPort(configuration.getPort());
server.addListener(listener);
ServletHttpContext servletContext = new ServletHttpContext();
servletContext.setContextPath("jsunit");
servletContext.setResourceBase(configuration.getResourceBase().toString());
servletContext.addServlet("JSP", "*.jsp", JspServlet.class.getName());
servletContext.addHandler(new ResourceHandler());
ConfigurationManager.clearConfigurationProviders();
ConfigurationManager.addConfigurationProvider(new XmlConfigurationProvider(xworkXmlName()));
com.opensymphony.webwork.config.Configuration.set("webwork.action.extension", "");
for (String servletName : servletNames())
addWebworkServlet(servletContext, servletName);
server.addContext(servletContext);
if (Monitor.activeCount() == 0)
Monitor.monitor();
}
示例2: start
import org.apache.jasper.servlet.JspServlet; //导入依赖的package包/类
public void start() {
final int port = ConfigurationManager.getConfigInstance().getInt(RSSConstants.JETTY_HTTP_PORT, Integer.MIN_VALUE);
final Context context = new Context(jettyServer, "/", Context.SESSIONS);
context.setResourceBase(RSSConstants.WEBAPPS_DIR);
context.setClassLoader(Thread.currentThread().getContextClassLoader());
context.addServlet(JspServlet.class, "*.jsp");
// Enable hystrix.stream
context.addServlet(HystrixMetricsStreamServlet.class, RSSConstants.HYSTRIX_STREAM_PATH);
final Server server = new Server(port);
server.setHandler(context);
try {
karyonServer.start();
server.start();
} catch (Exception exc) {
throw new RuntimeException("Cannot start karyon server ...", exc);
}
}
示例3: executeApp
import org.apache.jasper.servlet.JspServlet; //导入依赖的package包/类
@Override
public void executeApp() throws Exception {
int port = getAvailablePort();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("target/tomcat");
tomcat.setPort(port);
Context context =
tomcat.addContext("", new File("src/test/resources").getAbsolutePath());
WebappLoader webappLoader = new WebappLoader(RenderJspInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
Tomcat.addServlet(context, "hello", new ForwardingServlet());
context.addServletMapping("/hello", "hello");
Tomcat.addServlet(context, "jsp", new JspServlet());
context.addServletMapping("*.jsp", "jsp");
tomcat.start();
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + "/hello")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
tomcat.stop();
tomcat.destroy();
}
示例4: EmbeddedJspServer
import org.apache.jasper.servlet.JspServlet; //导入依赖的package包/类
public EmbeddedJspServer( Integer port, String webappFolder ) {
if (port == null) {
port = 8080;
}
_server = new Server(port);
try {
ServletHandler servletHandler = new ServletHandler();
_server.setHandler(servletHandler);
configureServletHandler(servletHandler);
// add jsp servlet mappings
String[] jspExtensions = {"*.jsp", "*.jspf", "*.jspx", "*.xsp", "*.JSP", "*.JSPF", "*.JSPX", "*.XSP"};
Class<JspServlet> jspServletClass = org.apache.jasper.servlet.JspServlet.class;
for( String jspExt : jspExtensions ) {
ServletHolder servletHolder = servletHandler.addServletWithMapping(jspServletClass, jspExt);
servletHolder.setInitParameter("logVerbosityLevel", "INFO");
servletHolder.setInitParameter("fork", "false");
servletHolder.setInitParameter("keepgenerated", "true");
// servletHolder.setInitParameter("keepgenerated", "true");
// <load-on-startup>0</load-on-startup>
}
if (webappFolder != null) {
webapp = getWebAppContext(_server, webappFolder);
configureWebAppContext(webapp);
_server.setHandler(webapp);
}
} catch (Exception e) {
e.printStackTrace();
LOG.log(Level.ALL, "Error", e);
}
}
示例5: setUp
import org.apache.jasper.servlet.JspServlet; //导入依赖的package包/类
@Before
public void setUp() {
tester.setResourceBase("./src/main/webapp/jsp");
tester.addServlet(JspServlet.class, "*.jsp");
tester.addServlet(textInput.class, "/servlet/*");
try {
tester.start();
} catch (Exception e) {
e.printStackTrace();
}
AbstractTaintUtil.setThrowException(false);
}
示例6: bind
import org.apache.jasper.servlet.JspServlet; //导入依赖的package包/类
/**
* A bind method for setting up the web location to use for JSP servlets and static files.
* Only one bind can be performed at this time.
* @param theDiskBase the location on disk, relative to the starting directory, where to find files from
* @param theWebBase the location in the URL, relative to the service location, where the system will service from
*/
public void bind( String theDiskBase, Map<String,String> theInitParameters ) {
Preconditions.checkState( !didBind, "Cannot bind a web location to interface '%s' because a location was already bound.", this.getName() );
Preconditions.checkState( this.getState() == ExecutionLifecycleState.CREATED || this.getState() == ExecutionLifecycleState.STARTING, "Cannot bind a web location to interface '%s' while it is in the '%s' state.", this.getName(), this.getState( ) );
Preconditions.checkArgument( !Strings.isNullOrEmpty( theDiskBase ), String.format( "Website interface '%s' needs a disk location.", getName( ) ) );
// information on parameters can be found here: http://wiki.eclipse.org/Jetty/Howto/Configure_JSP
// setup our resources and base class loader
this.getServletContext().setResourceBase( theDiskBase );
this.getServletContext().setClassLoader( Thread.currentThread().getContextClassLoader());
logger.info( "Binding web location on interface '{}' from path '{}' to http path '{}'.", this.getName(), theDiskBase, this.getServletContext().getContextPath( ) );
String webBase = "/";
// first we setup the default contract/servlet for handling regular static images and files
Servlet defaultServlet = new DefaultServlet();
HttpContract defaultContract = new HttpServletContract( getName( ) + "_web_default", "The default servlet for handling non-JSP files", new String[] { "20130201" }, defaultServlet, webBase );
this.getContractManager( ).register( defaultContract );
ContractServletHolder defaultHolder = new LaxContractServletHolder( defaultContract, defaultServlet, this );
this.getServletContext().addServlet( defaultHolder, "/" );
// next we setup the jsp contract/servlet for handling jsp files
JspServlet jspServlet = new JspServlet();
HttpContract jspContract = new HttpServletContract( getName( ) + "_web_jsp", "The jsp servlet for handling JSP files", new String[] { "20130201" }, jspServlet, webBase );
this.getContractManager( ).register( jspContract );
ContractServletHolder jspHolder = new LaxContractServletHolder( jspContract, jspServlet, this );
this.getServletContext().addServlet( jspHolder, "*.jsp" ); // TODO: this should be relative somehow
// we need to set up the init parameters, and will
// treat the class path specially, since we need it
boolean foundClasspath = false;
if( theInitParameters != null ) {
for( String name: theInitParameters.keySet( ) ) {
jspHolder.setInitParameter( name, theInitParameters.get( name ) );
if( String.CASE_INSENSITIVE_ORDER.compare( name, "classpath" ) == 0 ) {
foundClasspath = true;
}
}
}
// if we don't have a class path set then we need to set it
if( !foundClasspath ) {
jspHolder.setInitParameter( "classpath", this.getServletContext( ).getClassPath( ) );
}
}
示例7: createHandlers
import org.apache.jasper.servlet.JspServlet; //导入依赖的package包/类
private HandlerCollection createHandlers() throws IOException, URISyntaxException {
webAppContext = new WebAppContext();
webAppContext.setParentLoaderPriority(true);
webAppContext.setContextPath(contextPath);
webAppContext.setResourceBase(resourceBaseDirectory.getAbsolutePath());
File tempDir = new File(System.getProperty("java.io.tmpdir"));
File scratchDir = new File(tempDir.toString(), "embedded-jetty-jsp");
if (!scratchDir.exists()) {
if (!scratchDir.mkdirs()) {
throw new IOException("Unable to create scratch directory: " + scratchDir);
}
}
System.setProperty("org.apache.jasper.compiler.disablejsr199", "false");
ClassLoader jspClassLoader = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
webAppContext.setClassLoader(jspClassLoader);
ServletHolder holderJsp = new ServletHolder("jsp", JspServlet.class);
holderJsp.setInitOrder(0);
holderJsp.setInitParameter("logVerbosityLevel", "DEBUG");
holderJsp.setInitParameter("fork", "false");
holderJsp.setInitParameter("xpoweredBy", "false");
holderJsp.setInitParameter("compilerTargetVM", "1.7");
holderJsp.setInitParameter("compilerSourceVM", "1.7");
holderJsp.setInitParameter("keepgenerated", "true");
webAppContext.addServlet(holderJsp, "*.jsp");
webAppContext.addServlet(holderJsp, "*.jspf");
webAppContext.addServlet(holderJsp, "*.jspx");
webAppContext.setAttribute("javax.servlet.context.tempdir", scratchDir);
webAppContext.setConfigurations(new Configuration[]{
new WebXmlConfiguration(),
new AnnotationConfiguration() {
@Override
public void preConfigure(WebAppContext context) throws Exception {
MultiMap<String> map = new MultiMap<>();
map.add(WebApplicationInitializer.class.getName(), initializer.getName());
context.setAttribute(CLASS_INHERITANCE_MAP, map);
_classInheritanceHandler = new ClassInheritanceHandler(map);
}
}});
List<Handler> _handlers = new ArrayList<>();
_handlers.add(webAppContext);
HandlerList _contexts = new HandlerList();
_contexts.setHandlers(_handlers.toArray(new Handler[0]));
HandlerCollection _result = new HandlerCollection();
_result.setHandlers(new Handler[]{_contexts});
return _result;
}