Solved

Refresh the page and using session.

Posted on 2004-04-04
16
3,511 Views
Last Modified: 2012-08-14
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
Comment
Question by:YvonneYap
  • 5
  • 4
  • 4
  • +1
16 Comments
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10751827
>>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
 

Author Comment

by:YvonneYap
ID: 10752246
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
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10752248
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:YvonneYap
ID: 10752592
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
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10752642
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
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10752644
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
 
LVL 6

Accepted Solution

by:
jarasa earned 50 total points
ID: 10756143
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
 
LVL 6

Expert Comment

by:jarasa
ID: 10756157
Forget about the session thing I didn't notice that you only wanted for that JSP.
Javier
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10758758
>> 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
 
LVL 6

Expert Comment

by:jarasa
ID: 10763818
>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
 
LVL 14

Expert Comment

by:kennethxu
ID: 10766151
>> 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
 
LVL 6

Expert Comment

by:jarasa
ID: 10766182
>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
 
LVL 14

Expert Comment

by:kennethxu
ID: 10766185
why it's a B grade again?
and copyPasteGhost's initial answer was also correct.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10766200
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
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10818465
yeah I was thinking the same thing..
thanks ken :)
cheers
Ghost
0
 

Author Comment

by:YvonneYap
ID: 10822688
hey please la... people want to give is people business right. So childish...
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running Java Servlet inside Eclipse Luna 6 158
How to group array of objects ? 5 65
error when compiling my project in eclipse luna 30 412
print map entry 34 69
If you thought ransomware was bad, think again! Doxware has the potential to be even more damaging.
Google always has something new and amazing up its sleeve, and the most current thing that they have been working on is another step in the evolution of Google Search, from machine learning to its brilliant successor, deep learning.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question