This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Display jsp result in header without effecting the body  RSS feed

 
Marsoni Hutao
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've a jsp that get the sum from a database. and i want to show this on every webpage the user opens in header. Here totally there are 8 pages, right from the time the index page is opened, let it be any page the user opens, the header should be fixed. My current code is as below.

Index.jsp




and my Servlet is as below



Here everything is working fine. But the problem comes up with when i have multiple pages

I need the same above mentioned header in all the files. If i use a separate file and use a <jsp:include file/>, the entire page gets reloaded as a new page and shows the contents of new page.

Below example will give a better understanding.

I've 2 pages Index, counts these are JSPs.

There is some content in both index page, and the counts page is responsible for displaying counts (in the header) and it done in js using onload method.

When i run my program. The Index page is shown with its content and there would be a redirect to the counts.jsp and the content of counts.jsp is shown as a seperate jsp file, and the contents of index will be missing.

please let me know how can i do it. I want the result to be displayed in the header section itself without missing the body content.

A simple comparison would be with the frames that we use earlier. When we have a frame in header, what ever operations are done will be done there itself, it won't affect the entire age.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66186
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want a page reload, fetch the count using Ajax, retiring the value as a JSON response. Use the value obtained to update the DOM rather than reload the entire page.

JSP is not needed for any of this unless you need JSP for something else.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And do yourself a big favor and look into using jQuery. It pains me to see anyone writing raw JavaScript. It's like trying to build a house with a rock and a dull knife. You'll get it done eventually, but why put yourself through the agony when there are much better tools available?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!