Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reload jsp page using Ajax

 
duhit Choudhary
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i am new in jsp and i want to reload jsp page say one.jsp in which i have to change a div (content) with another jsp page say two.jsp. i also want to do this by using ajax. if anybody can help to tell how to do that would be very good.

thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Easiest way would be to use jQuery and its .load() method.
 
sourav jain
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following scriptlet code adds a Refresh header that specifies a 60-second interval for refreshing the JSP. Place this code at the top of the JSP before any content appears:

<% response.addHeader("Refresh","60"); %>

If you want to refresh the JSP to another web component or page, use this syntax:

<% response.addHeader("Refresh","10;
http://localhost:8080/home/thanks.jsp"); %>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sourav jain wrote:The following scriptlet code adds a Refresh header...

That will cause the whole page to refresh. It will not help the OP who has requested that only part of the page be refreshed via Ajax.

(P.S. Refreshing the whole page needlessly is a poor practice that has been obsolete since the advent of Ajax.)
 
sourav jain
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi i found solution. i am refresh the date.jsp page into div (id="t") of test.jsp without reloading test.jsp page

Test.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>

<script type="text/javascript" src="js/jquery.js">
</script>

<script type="text/javascript">


var i = setInterval(function(){

$("#t").load("date.jsp");
},1000);








</script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>

</head>
<body>

<div id="t">
<jsp:include page="date.jsp" ></jsp:include>

</div>

<p> hi </p>
</body>
</html>


2) date.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Date d = new Date();
SimpleDateFormat sp = new SimpleDateFormat("hh:mm:ss");
String t= sp.format(d);
out.print(t);



%>
</body>
</html>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic