This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Refresh Child Page  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have 2 Jsp Pages.
1.Parent.jsp
2.Child.jsp

Here i want to refresh Child.jsp from Parent.jsp.

Regards,
Eswara.L
 
Author
Posts: 114
11
Java Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are servlets that execute on the server. The response from a JSP (which could be HTML) is sent to a browser and displayed. This is a typical (but not the only) scenario.

What is the functionality that you wish to implement? Would you post you attempt so far!
 
Mahi Ranga
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here I am Posting 2 files.I want to display child incremented value in parent page every 1 sec.


Parent.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Parent JSP</title>
<script type="text/javascript" src="../js/jquery.min.js"></script>

<script type="text/javascript">
var url = 'Child.jsp'
$(document).ready(function() {
alert("1");
setInterval(function() {$("#load_me").load(url); }, 1000);
alert("2");
});
</script>
</head>
<body>
<div id="load_me">
<%=session.getAttribute("JVal")%>
</div>
<%! int i = 0;%>
<% i++;%>
I Value :<%=i%>
</body>
</html>


Child.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Child JSP</title>
</head>
<%! int j = 0;%>
<body>
<h1>Child JSP!</h1>
<%
System.out.println(j++);
session.setAttribute("JVal", j);
%>
<%--<jsp:forward page="Parent.jsp"></jsp:forward>--%>
</body>
</html>



Regards,
Eswara.L
 
Alex Theedom
Author
Posts: 114
11
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what your code is doing.

1. The parent page sets up a timer that calls the child.jsp every second
2. The child.jsp increments the value of j by one and returns HTML code containing the incremented value
3. The jQuery .load() replaces the <div id="load_me"> ... </div> with the HTML generated by child.jsp
4. Repeats every second.

There are few comments to make with regard to the code and some things that don't make sense.

- The session variable JVal should be set first in the parent not the child.
- Its not clear why you have are storing the value of i in the session, it is not retrieved again by parent.jsp as this page in not being reloaded.
- perhaps to maintain this value so that it can be incremented. For this you would need to get the session value before incrementing, which you are not doing.
- The code



will not be evaluated again unless the parent page is reloaded, which is not what you are doing.
- The Child.jsp returns a complete HTML page when all you need is the new value. This can be better achieved with a servlet.

Something like this:



Try to rewrite the code a bit and let me know what happens.

PS: When posting code use encoding to make the code easier to read. Thanks.

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!