Atitit。Web server Jetty9 使用 attilax 总结
1.1. 静态文件的资源
WebAppContext context = new WebAppContext();
// context.setcon
context.setContextPath("/");
context.setResourceBase(webAppPath); // "c:\0e"
context.addServlet(new ServletHolder(new WrmiServlet()), "/wrmiServlet");
server.setHandler(context);
1.2. Servlet使用
context.addServlet(new ServletHolder(new WrmiServlet()), "/wrmiServlet");
作者:: ★(attilax)>>> 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://www.cnblogs.com/attilax/
1.3. code
package aaaAddr;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
//import jcifs.smb.SmbFile;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
import org.slf4j.helpers.MessageFormatter;
import org.eclipse.jetty.webapp.WebAppContext;
import com.attilax.io.filex;
import com.attilax.io.pathx;
import com.attilax.lang.Global;
//import com.attilax.net.urlEncode;
import com.attilax.web.UrlX;
import com.attilax.wrmi.WrmiServlet;
/**jetty 9.3.7
* aaaAddr.jetty4xssServer
* @author Administrator
*
*/
public class jetty4boxSys extends AbstractHandler
{
// private String smb;
public void handle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
System.out.println("--taget:"+target); ///wrmiServlet zosh uri
if(target.equals("/wrmiServlet"))
new WrmiServlet().service(request, response);
// response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
}
private void convertStream(InputStream in,
OutputStream out) {
// InputStream in = new FileInputStream(srcFile);
// out = new FileOutputStream(destFile);
byte[] buffer = new byte[1024];
int byteread;
try {
while ((byteread = in.read(buffer)) != -1) {
out.write(buffer, 0, byteread);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(e);
}
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* http://127.0.0.1:7777/?smb=smb%3A%2F%2F192.168.2.106%2Fe%2F%E9%9D%9E%E8%93%9D%E5%85%89%2F9%E8%B7%AF%E5%86%A5%E5%A9%9A%2F9%E8%B7%AF%E5%86%A5%E5%A9%9A-fanart.jpg
* http://127.0.0.1:7777/?smb=smb%3A%2F%2F192.168.2.106%2Fe%2F%E9%9D%9E%E8%93%9D%E5%85%89%2F9%E8%B7%AF%E5%86%A5%E5%A9%9A%2F9%E8%B7%AF%E5%86%A5%E5%A9%9A.mkv
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception
{
System.setProperty("iocName","aaaCfg.Ioc4timer");
Global. iocCur="aaaCfg.Ioc4timer";
// HttpSessionIdListener
//HttpSessionIdListener
//MessageFormatter.arrayFormat(messagePattern, argArray)
System.setProperty("prj","jobus");//指明是运行的哪个项目
Server server = new Server(8009);
// ServletContextHandler
WebAppContext context = new WebAppContext();
// context.setcon
context.setContextPath("/");
try {
Object resourceBase; //jetty4boxSys.class.getResource(resourceBase).toURI().toASCIIString()
String webAppPath = pathx.webAppPath();
//webAppPath=com.attilax.net.URLEncoder.encode(webAppPath);
//URI uri=new URI(webAppPath);
//String resBase = uri.toString();
System.out.println(webAppPath);
context.setResourceBase(webAppPath); //"c:\0e"
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
context.addServlet(new ServletHolder(new WrmiServlet()), "/wrmiServlet");
server.setHandler(context);
// server.setHandler(new jetty4boxSys());
server.start();
System.out.println("--staered jetty9.3.7");
server.join();
System.out.println("--f");
}
//private jettyFileServer setSmb(String smb) {
//this.smb=smb;
//return this;
//}
}
------finish