Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3521
  • Last Modified:

Refresh the page and using session.

1. What is the coding to refresh or reload the jsp page?

2. What is the coding for session to maintain only 10 minutes on that jsp page.
0
YvonneYap
Asked:
YvonneYap
  • 5
  • 4
  • 4
  • +1
1 Solution
 
copyPasteGhostCommented:
>>1. What is the coding to refresh or reload the jsp page?

The following tag loads the page foo.html after 5 seconds.
<META HTTP-EQUIV="Refresh" CONTENT="5;URL=http://www.somehost.org/foo.html">
To cause a reload on the same resource, don't specify the alternative URL.

>>2. What is the coding for session to maintain only 10 minutes on that jsp page.

HttpSession hsObj = request.getSession(); hsObj.setMaxInactiveInterval(600);

the setMaxInactiveInterval accepts the amount of seconds. therefore 10 min = 60 X 10 = 600 seconds

cheers,
Ghost
0
 
YvonneYapAuthor Commented:
I have try the refresh coding but it keep on prompting the alert message in Internet Explorer saying that the page cannot be refresh without resending the information. Click retry to send the information or cancel to return the page u are viewing... How to prevent the alert message from coming out?
0
 
copyPasteGhostCommented:
jsp is a server side language...that means the the code is generated on the server and then sent to the client as html..

I don't think that you can reload the page without resending the information to the server?

why exactly do you want to refresh the page? maybe there is another way to do what you want to do..
Ghost
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
YvonneYapAuthor Commented:
hmm... Actually i am retrieving the data from the database and display the data to the JSP page. Then I can edit the JSP page to update some of the data... Example, (retrieve from database) address: Jurong. When i change the address: Yishun and click on the update button, it will update the data to my database then come to a JSP page where all my updated data displayed. Now the problem come... the JSP page display address: Jurong first instead of Yishun which i have already updated. But when i click on refresh, it give me the address: Yishun.  I am not suppose to click on the refresh in order to get my data display correct.... that is why i want coding for the reload on that particular jsp page. Do you have any suggestion like using the javascript reload method or other suggestion?  If have, provide the coding please...
0
 
copyPasteGhostCommented:
ummm I have an idea... you can do this...

if this is your .....form.jsp
<%
sqlQuery = ("Select FirstName,LastName FROM myTable");
rs = statement.executeQuery(sqlQuery);
areMore = rs.next();
String fName = "";
String lName = "";
if (areMore) {
  do {
    fName = rs.getString("FirstName");
    lName = rs.getString("LastName");
  } while ( rs.next() );  
}  
%>

<html>
 <body>
   <form method="post" action="update.jsp">
     <table>
       <tr>
         <td>*First Name</td>
         <td><input type="text" name="fName" size="30" value="<%= fName%>" /></td>
       </tr>
       <tr>
         <td>*Last Name</td>
         <td><input type="text" name="lName" size="30" value="<%= lName%>" /></td>
       </tr>
     </table>
   </form>
 </body>  
</html>

and then this is your: update.jsp

<%
String fName = request.getParameter("fName");
String lName = request.getParameter("lName");

sqlQuery = ("Update myTable set FirstName = '" + fName+ "',LastName = '" + lName+"'");
statement.executeUpdate(sqlQuery);

%>
<jsp:forward page="form.jsp" />

YOU MUST REMEMBER TO ADD A WHERE Clause on the UPDATE statement or else every field in your database will be changed..

try that and let me know,
Ghost
0
 
copyPasteGhostCommented:
oh yeah the reload function for javascript will still make you have to answer that "resubmit" question box...

I think the way I suggested will fix your problems,
Ghost
0
 
jarasaCommented:
Try putting this on your JSP page
<%
      response.setHeader("Cache-Control", "no-cache");
      response.setHeader("Pragma", "no-cache");
      response.setDateHeader("max-age", 0);
      response.setDateHeader("Expires", 0);
%>
I thing your problem is with the Cache not with the data.

Javier

About the session exipiration, you can set it on web.xml in /conf dir if you're using TOMCAT

  <!-- ==================== Default Session Configuration ================= -->

  <!-- You can set the default session timeout (in minutes) for all newly   -->
  <!-- created sessions by modifying the value below.                       -->

  <session-config>
    <session-timeout>10</session-timeout>
  </session-config>

Javier
0
 
jarasaCommented:
Forget about the session thing I didn't notice that you only wanted for that JSP.
Javier
0
 
kennethxuCommented:
>> Forget about the session thing I didn't notice that you only wanted for that JSP.
no, once you set seesion on one jsp, it sets for all other pages in the same session. so it is almost the same between setting in jsp and web.xml.
0
 
jarasaCommented:
>no, once you set seesion on one jsp, it sets for all other pages in the same session. so it is almost the same >between setting in jsp and web.xml.

I know kenneth but if you have it on web.xml it will be the same for all applications on the server, right?

If you set the timeout on each application start page it would be different as long as you open each with a differen browser, Tha's why I said to forget it.

:c)

Javier
0
 
kennethxuCommented:
>> but if you have it on web.xml it will be the same for all applications on the server, right?
no, it's per webapp configuration, you only change the web.xml of the application you want to change.
0
 
jarasaCommented:
>no, it's per webapp configuration, you only change the web.xml of the application you want to change.
Kenneth I'm talking about the /conf/web.xml not /WEB-INF/web.xml

0
 
kennethxuCommented:
why it's a B grade again?
and copyPasteGhost's initial answer was also correct.
0
 
kennethxuCommented:
if asker don't give reason for B grade in next few days. I'll report to EE admin.
http://www.experts-exchange.com/Web/Web_Languages/JSP/help.jsp#hi73
0
 
copyPasteGhostCommented:
yeah I was thinking the same thing..
thanks ken :)
cheers
Ghost
0
 
YvonneYapAuthor Commented:
hey please la... people want to give is people business right. So childish...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now