标签:style blog http io color os ar java sp
jetty是一个轻便的嵌入式servlet容器。其启动运行非常简单。eclipse下运行jetty容器有如下几步,
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
package test; import org.mortbay.jetty.Connector; import org.mortbay.jetty.Server; import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.webapp.WebAppContext; public class Bootstart { public static void main(String[] args) throws Exception { Server service = new Server(); Connector connector = new SelectChannelConnector(); //设置端口 connector.setPort(8080); //设置host地址 connector.setHost("127.0.0.1"); service.setConnectors(new Connector[] { connector }); //设置根路径 WebAppContext context = new WebAppContext("web", "/web"); service.addHandler(context); service.setStopAtShutdown(true); service.setSendServerVersion(true); //启动服务 service.start(); service.join(); } }
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <% request.setAttribute("name","sun"); System.out.println("My name is:" + request.getAttribute("name")); %> </body> </html>
标签:style blog http io color os ar java sp
原文地址:http://www.cnblogs.com/zenghansen/p/4059106.html