0

I want to develop a application and deploy in WebSphere where the requirement is:

if there are any request like http://appserver1:9080/ - it will reach to a landing jsp page

for example http://appserver1:9080/index.jsp

Is it at all possible to redirect to a page even if I don't mention the resource name?

Vishal Gajera
  • 4,137
  • 5
  • 28
  • 55
paularka90
  • 23
  • 1
  • 7

3 Answers3

1

If you want to redirect from server's root, this is not about your java code or project configuration, it is about server configuration. Look here for WebSphere configuration.

For JEE projects, on web.xml, you can define as;

<web-app>  
 ....  

  <welcome-file-list>  
   <welcome-file>index.jsp</welcome-file>  
   <welcome-file>default.html</welcome-file>  
  </welcome-file-list>  
</web-app>  

So

http://localhost:8080/myproject

will load index.jsp

Source for details

Community
  • 1
  • 1
Yusuf K.
  • 4,195
  • 1
  • 33
  • 69
  • Thanks for the response. The above is working fine. But the requirement actually is this, I will just invoke the URL: http://localhost:8080/ and this will redirect me to my landing page for example home.jsp. I want to know whether it is possible if I don't mention the /myproject name in the URL. – paularka90 Mar 29 '16 at 11:19
  • 1
    @paularka90 Ok this is not about your java code or project code. this is about your server configuration. For websphere, see http://stackoverflow.com/a/26874378/517134 it may help. – Yusuf K. Mar 29 '16 at 11:59
1

From what you are describing, the redirection can be pretty much handled by servlets mapping. Read here:

https://docs.oracle.com/cd/E13222_01/wls/docs92/webapp/configureservlet.html

You can be able to intercept URL requests and process:

// Servlet definition on your web.xml

<servlet>
<servlet-name>ServletHandler</servlet-name>
<servlet-class>com.servlets.ServletHandler</servlet-class>
</servlet>

// This maps all requests to the above defined servlet for processing:

<servlet-mapping>
<servlet-name>ServletHandler</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

I hope this helps

ArnoldKem
  • 100
  • 2
0

You can define welcome files in web.xml

<web-app>
    ...
    <welcome-file-list>
        <welcome-file>index.jsp/welcome-file>
    </welcome-file-list>
    ...
</web-app>

But according to the spec index.html, index.htm and index.jsp are welcome files by default. So you probably don't need to configure anything when the file is called index.jsp.

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82