Equinox Servlet
来源:互联网 发布:孕妇装 知乎 编辑:程序博客网 时间:2024/05/29 15:58
本例采用扩展点的方式,注册Servlet和web资源。
Step1: 建立Eclipse plugin-in工程
Step2: 新建一个Servlet类
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloServlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
resp.getWriter().println("hello");
}
}
Step3: Eclipse提示HttpServlet找不到,在MANIFEST.MF中添加对javax.servlet的依赖
后两项是扩展点中注册servlet时需要的bundle;
Step4: 在项目根目录下新建WebContent目录,并新建jsp目录,index.jsp文件
index.jsp文件
<%@ 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>
index...........
</body>
</html>
Step5: 在项目根目录下新建plugin.xml(在MANIFEST.MF的overview中点击Extensions链接可自动生成)
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.equinox.http.registry.resources">
<resource
alias="/images"
base-name="/WebContent/img"/>
</extension>
<extension point="org.eclipse.equinox.http.registry.servlets">
<servlet
alias="/hello"
class="servlet.HelloServlet"
load-on-startup="true">
</servlet>
<servlet
alias="/jsp/*.jsp"
class="org.eclipse.equinox.jsp.jasper.registry.JSPFactory:/WebContent/jsp/"/>
</extension>
</plugin>
Step6: Run Configure
新建一个OSGi Framework
取消Bundles的Target Platform, 点击Add Required Bundles:只需要添加我们需要的bundle。
注意,添加jetty
org.eclipse.equinox.http.jetty是手动添加的,其余的是add required Bundles自动添加的
Step7: run
在控制台中执行ss命令
osgi> ss
我们的bundle的状态时ACTIVE,表示已经可用;
在浏览器中,访问http://localhost/hello, http://localhost/jsp/index.jsp,http://localhost/images/1.jpg
Step8: 更新源码
更新源码时,Eclipse不会自动刷新bundle,可以通过命令update 5(5是bundle的bundleID)强制执行
- Equinox Servlet
- OSGI运行Servlet(使用Equinox框架)
- equinox
- OSGi——运行工具箱的配置(org.eclipse.equinox.http org.eclipse.equinox.servlet.api)问题
- Equinox简介
- Equinox介绍
- Equinox OSGi
- Equinox P2
- Equinox OSGi系列之一 Equinox入门
- Equinox OSGi系列之一 Equinox入门
- Equinox OSGi系列之一 Equinox入门
- Eclipse的核心 - Equinox
- Server Side Equinox
- Server Side Equinox
- 我也来玩Equinox(一)
- 我也来玩Equinox(二)
- 我也来玩Equinox(三)
- OSGI之Debug Equinox
- FCT跟踪总结
- 静态库的创建和使用
- 为Vs2010配置OpenGL使用环境
- Java笔记一:Java技术
- ubuntu 初次安装2002问题
- Equinox Servlet
- Android10_ListView,Adapter,List(或者数组)的关系
- (Eclipse打包问题)Export aborted because fatal lint errors
- 例子2之解决ORA-03113: 通信通道的文件结尾(实质是Control filesequence number mismatch)
- 编程中遇到的错误
- TFTlcd显示屏驱动
- android KK2的中国移动/中国联通定制版本移除Gallery2.apk
- ORA-31693:Table data object xxx failed to load
- 猜数字