user3240810
user3240810

Reputation: 21

How to get init parameter of servlet at web.xml from welcome jsp page?

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?

Upvotes: 2

Views: 1118

Answers (2)

Mikkel Løkke
Mikkel Løkke

Reputation: 3749

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.

Upvotes: 2

lorinpa
lorinpa

Reputation: 556

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.

Upvotes: 2

Related Questions