0

In my java ee project I mapped welcome page as

<welcome-file-list>
    <welcome-file>Login.jsp</welcome-file>
</welcome-file-list>  

After login correctly I go to index.jsp. Which is my home. What I need is hide index.jsp in url. Only localhost://EMS.

Usually it doesn't show index.jsp in url. But sometimes I press back arrow key eventually I go to http://localhost:8080/EMS/index.jsp

Is there any way to hide that? I'm not using any java related frameworks at the moment. Also I use apache tomcat.

Naman Gala
  • 4,670
  • 1
  • 21
  • 55
Dil.
  • 1,996
  • 7
  • 41
  • 68

3 Answers3

1

Yes, by using:

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

See "Configuring Welcome Files".

At the beginning of index.jsp, you need to check whether the user is logged in. If not, redirect to login.jsp. If you don't want the user to see login.jsp in the URL, you need to include the JSP instead.

If you want to make sure that the user never sees index.jsp, you need to check the request URL and redirect to / when the URL ends with /index.jsp using response.sendRedirect().

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • I tried this thing using index control servlet. And that servlet set to welcome-file. After go to servlet if session is not null then go to index.jsp. Which is "/". If session is empty I load back to login. Unfortunately it gave me a memory leak. – Dil. Aug 03 '15 at 08:22
  • The approach itself can't result in a memory leak. You have another bug in your code or you're not giving the VM enough memory to begin with. Without additional information, I can't help you. – Aaron Digulla Aug 03 '15 at 18:40
  • Yes it was happened because my project's another stupid buy. You method is perfect. Thank you. – Dil. Aug 04 '15 at 01:01
1

To do so you have to map your JSP file in web.xml file.

<servlet>
    <servlet-name>index</servlet-name>
    <jsp-file>path/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>index</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

You will be able to access the url http://localhost:8080/EMS/

Nisheeth Shah
  • 600
  • 1
  • 9
  • 22
0

I think you're better off making index.jsp your welcome page and checking whether a user is logged in, and redirecting to login.jsp from that page.

Davio
  • 4,609
  • 2
  • 31
  • 58