aspose file tools*
The moose likes JSP and the fly likes How to get dynamic content in index.jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to get dynamic content in index.jsp page" Watch "How to get dynamic content in index.jsp page" New topic
Author

How to get dynamic content in index.jsp page

chintu reddy
Greenhorn

Joined: Feb 13, 2010
Posts: 21
this is my first sevlet/jsp application.. so question might be dumb..

In my application, When the user opens the website, he will open index.jsp, now I have to get dynamic content inside this page. But the problem is that he is not requesting any servlet as of yet.. So how to get dynamic content in first page ?
one option was to, create index.jsp and redirect it to a servlet.. that servlet gets all the information needed on first page and then redirects that info to "home.jsp".. is this good option? or are there any other options?
thanks in advanve


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

Redefine the "welcome file" to your servlet rather than index.jsp.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
chintu reddy
Greenhorn

Joined: Feb 13, 2010
Posts: 21
thanks Bier..

how to do that? is that done in web.xml?
chintu reddy
Greenhorn

Joined: Feb 13, 2010
Posts: 21
ok got it.. <welcome-file-list> in web.xml.. thanks
chintu reddy
Greenhorn

Joined: Feb 13, 2010
Posts: 21
one more question...

is it a good practice to give servlet paths in hyperlinks? i mean menu bar in each page has links to other pages. when the user clicks that link, that page opens with dynamic content.. right now i am giving path to servlet(defined in web.xml) and redirecting from there to a jsp page.. is there any other way to do it?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

Why would you want to do it any other way?
chintu reddy
Greenhorn

Joined: Feb 13, 2010
Posts: 21
lets say, a user wanted to check his course list.. there is a link on the menu bar "my course list"... right now im linking that to "courselist.do" and that redirects to courselist.jsp page

once a user opens that page url is saved in web history in the browser.. in case some clever (or stupid) user instead of going through the link on the menubar, directly enters the url to the jsp page then the jsp page loads but it doesn't show any content as no content was drawn from servlet... i was thinking how to get around this..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

I missed the part about redirecting. Why is your controller redirecting rather than forwarding?

Your JSP pages should also be hidden under WEB-INF so that they cannot be addressed via the browser.
chintu reddy
Greenhorn

Joined: Feb 13, 2010
Posts: 21
oh sorry.. i meant forward only.. not redirect......

so all the jsp pages that are supposed to be open after an action should be put under web-inf.. right?

thanks a lot
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

Not web-inf, WEB-INF.

If you forward rather than redirect, the address of the JSP is never exposed.
chintu reddy
Greenhorn

Joined: Feb 13, 2010
Posts: 21
Ok.. that solves my problem.. thanks a lot....

now my next quest is to learn tag libraries and use them to display content in jsps.. can you suggest me some good startup material.. i have absolutely no idea abt tag libraries.. very difficult to understand the working procedure from sun's tutorial...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

"abt"?
chintu reddy
Greenhorn

Joined: Feb 13, 2010
Posts: 21
about
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get dynamic content in index.jsp page