2

I created index.jsp page and binded path /index to it in web.xml.
It's also displayed when accessing the root of application as welcome page. It has three init parameters.

The problem is I can access then from JSP code by config.getInitParameter() if the path is full [host:port]/[appName]/index, the parameters are accessed normally.
If I try to navigate to application root [host:port]/[appName]/ welcome page is displayed but init parameters can't be accessed. config.getInitParameter() method returns null.

How to configure welcome page properly in web.xml if I want to get servlet init parameters?

Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45

2 Answers2

2

Do you have index.jsp defined as a "welcome-file" in web.xml? It sounds like the container is doing a redirect. Defining index.jsp as a welcome-file should fix that.

Hope that helps.

lorinpa
  • 556
  • 1
  • 5
  • 6
  • Thank you for the response. Can you post your web.xml? Have you traced the route from a web browser request to your servlet (both scenarios)? Can you you post the http response codes? – lorinpa Jan 28 '14 at 14:13
2

Usually in Java, if you want to use / to access a Java EE context, you would either:

  1. Mount it on the ROOT context.
  2. Use a reverse proxy (like nginx).

The second method is the most common solution. In this case the request goes Browser -> Reverse Proxy / Load Balancer -> One or more application servers.

This has several advantages.

  1. You can handle SSL handshaking on the Reverse Proxy.
  2. Your application server can deliver content as fast as it can to the Reverse Proxy (which is usually faster than to the browser) so it doesn't tie up the connection as long (spoon feeding).
  3. You can display meaningful error pages even if the Java EE container isn't running.
  4. Having a different domain, or subdomain for serving each context is trivial.
Mikkel Løkke
  • 3,710
  • 23
  • 37
  • I can't use a proxy. It doesn't lay in my compitence. This is inner corparative server managed by sysadmins. I can only configure Jetty to rewrite URL from application root to index. But is it possible to configure application itself? – user3240810 Jan 28 '14 at 07:03
  • No. As a general rule of thumb Java Servlet Contexts are isolated for security reasons. If you're using jetty, just call your webapp root.war, and it will be mounted on the / context. Alternatively get your sysadmins to setup a reverse proxy for you. :) – Mikkel Løkke Jan 28 '14 at 08:48