我遇到问题。我想使用OSGi作为网站。我对OSGi相当陌生,但我已经阅读了基础知识并希望使用框架Equinox。为此,我从http://eclipse.org/equinox/阅读了快速入门指南,并购买了书籍“OSGi和Equinox - 创建高度模块化的Java系统”Web-Container中的OSGi - 请求的资源不可用(JSP文件)
但是回到我的问题。我从Equinox站点下载了bridge.war,并创建了第一个包含servlet的包。激活器是这样的:
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
httpServiceTracker = new HttpServiceTracker(context);
httpServiceTracker.open();
}
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
httpServiceTracker.close();
httpServiceTracker = null;
}
private class HttpServiceTracker extends ServiceTracker {
public HttpServiceTracker(BundleContext context) {
super(context, HttpService.class.getName(), null);
}
public Object addingService(ServiceReference reference) {
HttpService httpService = (HttpService) context.getService(reference);
try {
httpService.registerServlet("/index", new StartServlet(), null, null); //$NON-NLS-1$
} catch (Exception e) {
e.printStackTrace();
}
return httpService;
}
public void removedService(ServiceReference reference, Object service) {
HttpService httpService = (HttpService) service;
httpService.unregister("/index"); //$NON-NLS-1$
super.removedService(reference, service);
}
}
而且我的servlet是这样的:
保护无效的doGet(HttpServletRequest的请求,HttpServletResponse的响应)抛出了ServletException,IOException异常{ performTask(请求,响应); }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
performTask(request, response);
}
private void performTask(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
RequestDispatcher RequestDispatcherview = request.getRequestDispatcher("test.jsp");
RequestDispatcherview.forward(request, response);
}
JSP文件是在文件夹/的WebContent /这在捆绑。 如果我部署束引入Bridge.war,然后尝试在浏览器中打开网站,我总是得到如下:
我不知道我可以配置我的Servlet或者我的活化剂,他们会找到jsp文件。 我试图将JSP文件移动到bridge.war中,但它不能帮助我防止此问题。
我想我必须在任何地方注册jsp文件(可能与httpService.registerResources(arg0, arg1, arg2);
),但我不知道我是如何正确执行此操作的。
我希望你能帮助我。
你已经在“/ index”上下文中注册了你的servlet,你不应该在你的URL的某个地方有“index”吗? – 2014-12-05 11:57:44
如果我打开http:// localhost:8080/bridge/index,servlet将被激活,并且在servlet中,我尝试将请求发送到test.jsp,但servlet无法找到jsp文件。 – Baalthasarr 2014-12-05 14:20:06
另一方面,将您的Web应用程序部署到OSGi容器中。要么创建你自己的捆绑设置,要么使用Apache Karaf这样的OSGi容器。 – 2014-12-05 21:45:23