How to refresh JSP page?
Hi,
How can I refresh my JSP Page?
I am addind and deleting some mrecords with pressing button on my JSP page, but everytime I have to use browser's back button and hit refresh to see the updates.
How can I just refresh it every time I update the page..
Your help will be appreciated.
Thanks
[329 byte] By [
ASH_2007a] at [2007-11-27 7:51:46]

# 1
write an action which reloads(refersh) the page for a specified intervak of time.Using javascript
# 2
How can I do that?Could you explain with sample code please?Thanks
# 3
document.forms[0].submit(); make it as a js function and call when you add/delete an record.
skp71a at 2007-7-12 19:32:54 >

# 4
Why not everytime you delete something you redirect the user to the Updated page instead of clicking the back button....response.sendRedirect("PageName.jsp");hope that helps :)
# 5
hi avni,i think the problem is in cache.try to clear the cache and see check it.Bala
art84a at 2007-7-12 19:32:54 >

# 6
Response.sendRedirect is not working for me for somereasons, it says page could not be foundSo that's why Ia m looking for alternativeThanks
# 7
> document.forms[0].submit(); make it as a js function
> and call when you add/delete an record.
Hey skp71,
I am already calling JS function add and delete on onclick event of ADD and DELETE button.
I tried writting document.forms[0].submit(); in my function.
But id didn't work.
Could anyone help please?
Thanks
# 8
better post part of your code within blocks.
skp71a at 2007-7-12 19:32:54 >

# 9
hi avni,can u post your folder structure wgere the Jsp file is located.Bala
art84a at 2007-7-12 19:32:54 >

# 10
int i = delete_Customer(delName);
System.out.println("i:"+i);
if (i==1)
{
System.out.println("Sending response");
response.sendRedirect("/abc/CustomerList.jsp");
}
//
//
int delete_Customer(String delName) {
// TODO Auto-generated method stub
int i=0;
Statement stmt = null;
Connection con = null;
try
{
System.out.println("In Try block for Deleting values");
Class driverClass = Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
Driver driver = (Driver) driverClass.newInstance();
DriverManager.registerDriver(driver);
con = DriverManager.getConnection("jdbc:db2:" + DB2Server, DB2UserID, DB2pass);
stmt = con.createStatement();
System.out.println(delName);
String query =
"DELETE FROM CUSTOMERNAME WHERE Customer_Name = '" +delName.trim()+ "'";
System.out.println("Values Deleted");
i = stmt.executeUpdate(query);
System.out.println("Nrows="+i);
stmt.close();
con.close();
}
catch(Exception e)
{
System.out.println("EXCEPTION : "+e.toString());
try
{
System.out.println("Severe error in DELETE, unable to continue");
if(stmt != null)
stmt.close();
if(con != null)
con.close();
}
catch(SQLException se)
{
System.out.println(se.toString());
}
}
System.out.println("i:"+i);
return i;
}//delete method ends
This is my servlet code.
It's not throwing any error,
it's also going to my system log (sending response) but then it doesn't redirect it to the jsp page.
Thanks
# 11
hi,if u using doGet or doPost method.post that code alsoBala
art84a at 2007-7-12 19:32:55 >

# 12
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
String Cust_Name,DELETE;
DB2Server = props.getProperty("SERVER");
DB2UserID = props.getProperty("USER");
DB2pass =props.getProperty("PASS");
Cust_Name = null;
DELETE = null;
if((tStr = request.getParameter("CUSTOMER_NAME")) != null) {
Cust_Name = tStr;
}
if((tStr = request.getParameter("DELETE")) != null) {
DELETE = tStr;
}
if(DELETE !=null) {
if(DELETE.equals("DELETE")){
System.out.println("HW: DELETE Customer: " );
if((tStr = request.getParameter("Selected_names"))!= null){
System.out.println(tStr);
String delName="";
int pos = 0;
pos=tStr.trim().indexOf(",");
while ( pos != -1) //till there is atleast 1 ,
{
System.out.println("while loop");
delName = tStr.substring(0, tStr.indexOf(","));
tStr = tStr.substring(tStr.indexOf(",") + 1 );
System.out.println("DElName:"+delName);
System.out.println("tStr::"+tStr);
System.out.println("Customer names to be deleted are:"+delName.trim());
int i = delete_Customer(delName);
System.out.println("i:"+i);
if (i==1)
{
System.out.println("Sending response");
response.sendRedirect("/aaa/CustomerList.jsp");
}
delName = tStr.trim();
pos=tStr.indexOf(",");
}//while ends
}
}//2nd if ends
}//if ends
It's in doGet.
thanks
# 13
hi avni,the code is correct.r u using any IDE for development.Bala
art84a at 2007-7-12 19:32:55 >

# 14
It is a webservice application running on Tomcat. I am just using eclipse for development, not any specific IDE.
# 15
All,
all of a sudden, it started working if I just delete one record.
For more then one record I put if i>=1, but it didn't work
any idea? why?
Let me know
int i = delete_Customer(Cust_Name);
System.out.println("i:"+i);
System.out.println("check value of i");
if (i==1 || i>=1)
{
System.out.println("Sending response");
response.sendRedirect("/aaa/CustomerList.jsp");
}
I also trie if (i!= 0)
Thanks
# 16
hi avni,
here u can't acces that type condition.
int i = delete_name(name);
becoz, here the Value of i is only 1 or 0 based on the query exceution.
if the record is delete it returns 1 otherwiae it ll return 0
i think u ll catch my point.
Bala
art84a at 2007-7-21 22:23:22 >

# 17
Oh, I got your point.But if I select multiple data, it gets deleted from database but on server side it throws an error page.What to do for that?Thanks
# 18
It refresh it and works fins if u just delete one record
# 19
hi avni,
if u want to delete the multiple data in database in one click, i am right.
yes it can be possible.
we have an option in Java.SQL
that is executeBatch();
can u know about this
i think the below link is very useful for u.
http://jug.org.ua/wiki/display/JavaAlmanac/Executing+a+Batch+of+SQL+Statements+in+a+Database
Bala
art84a at 2007-7-21 22:23:22 >

# 20
Thanks Bala.and my name is Ash_2007 :-) So make it rightThanks