简体   繁体   中英

Registering Servlet on a Specified Port

I want to register a ServLet on a specified port, because my port 80 using by another programs that i need them and i can close and kill them. This is my code for registering 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();
                }

You can definitely only set the port of the HttpService itself, but it will never try to use port 80 by default. Would it be an idea to configure the server you've got at 80 to proxy certain parts to the OSGi service?

This stuff is a bit trickier than it seems. Getting all the web stuff working (especially more advanced stuff like Filters) isn't that easy.

Pax Web made it much easier. ( this bundle contains Jetty and all its dependencies, so you can remove the jetty you are using now)

The port can be configured using OSGi configuration, but by default it is on 8080.

No, this can only be done at container level. Which is your application server? For tomcat, check out the port parameter of the HTTP connector .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM