在指定端口上注册Servlet

时间:2013-12-13 15:43:40

标签: java servlets osgi

我想在指定的端口上注册一个ServLet,因为我的端口80使用了我需要的另一个程序,我可以关闭并杀死它们。 这是我注册servlet的代码:

 HttpService httpService = (HttpService) super.addingService(reference);
                if (httpService == null)
                        return null;

                try {
                        System.out.println("Registering servlet at /simple");
                        httpService.registerServlet("/simple", new SimpleServlet(), null,
                                        null);
                } catch (Exception e) {
                        e.printStackTrace();
                }

2 个答案:

答案 0 :(得分:1)

您绝对只能设置HttpService本身的端口,但默认情况下它永远不会尝试使用端口80。是否可以将您在80处获得的服务器配置为将某些部分代理到OSGi服务?

这个东西比看起来有点棘手。让所有网络内容工作(特别是像过滤器这样的更高级的东西)并不容易。

Pax Web让它变得更容易。 (this bundle包含Jetty及其所有依赖项,因此您可以删除当前使用的码头)

可以使用OSGi配置配置端口,但默认情况下它是8080。

答案 1 :(得分:0)

不,这只能在容器级别完成。哪个是你的应用服务器?对于tomcat,请查看HTTP connector的端口参数。

相关问题