• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 776
  • Last Modified:

Refreshing without retry dialogue box

Hi Exprts,

ACTION:

After login from PAGE1 the control transfer to PAGE2 which verify the login data and then it loads PAGE3 if
userid and pswrd is correct.

PAGE3 need to auto refresh every few seconds.

PROBLEM:

When PAGE3 auto-refresh a dialogue box appears with a message "The page can not be resent without resending the
information" then you have to press RETRY button to reload the page.

How can I avoid this dialogue box while auto refreshing the page?

------------------------------------------------- PAGE1 CODE ------------------------------------
<html>
<head>
<title>Login</title>
<body bgcolor="white">
<form method="POST" action="PAGE2.jsp" >
  <table border="0" cellspacing="5">
    <tr>
      <th align="right">Username:</th>
      <td align="left"><input type="text" name="usrid"></td>
    </tr>
    <tr>
      <th align="right">Password:</th>
      <td align="left"><input type="password" name="pswrd"></td>
    </tr>
    <tr>
      <td align="right"><input type="submit" value="Log In"></td>
      <td align="left"><input type="reset"></td>
    </tr>
  </table>
</form>
</body>
</html>
-----------------------------------------------------------------------------------------------------------

------------------------------------- PAGE2 CODE ------------------------------------------------------
<%
     String pswd = request.getParameter("pswrd");
     String uid = request.getParameter("usrid");

     if(verifypswdpolicy(pswd)){
         //out.print("Verified Done.");
         request.setAttribute("myvar", "vrfied");
%>
<jsp:forward page="PAGE3.jsp" />
<%
         
         //response.sendRedirect("testa1.jsp");
     } else {
         out.print("Invalid userid or password. ");
         out.print("<a href=\"PAGE1.jsp\">Click To Retry </a></p>");
         //response.sendRedirect("testlf.jsp");
     }
%>
----------------------------------------------------------------------------------------------------

--------------------------------------------< PAGE3 CODE >--------------------------------------

<script language="javascript">
 setTimeout("self.location.reload()",5000);
</script>


<%
   //String value = request.getParameter("myvar");
   out.print(" Value : " + request.getAttribute("myvar"));
%>

--------------------------------------------------------------------------------------------------------


When I use <meta http-equiv=Refresh content="5; url=http://127.0.0.1:8081/PAGE3.jsp" > the PAGE3
auto-refresh without dialogue box but the value of the variable "value" becomes NULL.
The value of "myvar" variable is needed to verify that user is coming from login page.


Any solution or work around?


Thanks.
0
myrizvi
Asked:
myrizvi
  • 6
  • 5
1 Solution
 
orhanbabaCommented:
<META HTTP-EQUIV=Refresh CONTENT="10; URL=http://www.domain.com/">
<META HTTP-EQUIV=Refresh CONTENT="10; URL=login.jsp">
10 is second
0
 
TimYatesCommented:
>> but the value of the variable "value" becomes NULL.

Because it is a different request, so the attribute is lost...

Either:

a)  Set the variable in the session, and then it will be kept between requests:

    session.setAttribute( "myvar", "vrfied" ) ;

b)  pass the variable as a request parameter

    <%
        String value = request.getAttribute( "myvar" ) ;
        if( value == null ) value = request.getParameter( "myvar" ) ;
    %>
    <meta http-equiv=Refresh content="5; url=http://127.0.0.1:8081/PAGE3.jsp?myvar=<%= value %>" >
0
 
myrizviAuthor Commented:
Thanks guys.

I will test and come back to you.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
TimYatesCommented:
No worries!  Hope I helped :-)

As you can see, what this does:

    <%
        String value = request.getAttribute( "myvar" ) ;
        if( value == null ) value = request.getParameter( "myvar" ) ;
    %>
 
is checks to see if the value is in the request ATTRIBUTES, and if it isn't, tries to get it out of the request PARAMETERS...

then the EQUIV-REFRESH passes this value back as a parameter when it refreshes...

so first time though it will be an attribute and from then on it will be a parameter :-)

You may need to encode the value if it contains spaces and suchlike...  using URLEncoder.encode

And if you don't want the parameter to be passed this way (as it will be visible in the URL when the refresh is done), as I said, you will need to use the session :-)

Good luck!!

Tim
0
 
myrizviAuthor Commented:
Hi TimYates,

----------------- ON PAGE2 I did -------------------

<%
     String pswd = request.getParameter("pswrd");
     String uid = request.getParameter("usrid");

     if(verifypswdpolicy(pswd)){
         session.setAttribute("myvar","vrfied");                  
%>
<jsp:forward page="testa1.jsp" />
<%
     } else {
         out.print("Invalid userid or password. ");
         out.print("<a href=\"testlf.jsp\">Click To Retry </a></p>");
         //response.sendRedirect("testlf.jsp");
     }
%>
--------------------------------------------------------------

---------------- ON PAGE3 I did: ---------------------------

<%
  String value = request.getAttribute("myvar");
   if( value == null ){
     value = request.getParameter("myvar");}

   out.print("value : " + value);
%>

<meta http-equiv=Refresh content="5; url=http://<host>:<port>/PAGE3.jsp?mmyvar=<%=value%>">
-----------------------------------------------------------------

----------------------- The ERROR I got ---------------------


[javac] Compiling 1 source file

Tomcat 4.1\work\Standalone\localhost\helloworld\testa1_jsp.java:55: incompatible types
found   : java.lang.Object
required: java.lang.String
   String value = request.getAttribute("myvar");
                                      ^
1 error
------------------------------------------------------------------

0
 
TimYatesCommented:
String value = (String)request.getAttribute("myvar");
0
 
myrizviAuthor Commented:
Thanks TimYates,

Now after this correction the RESULT is :

value : null


The variable receiving NULL value.
0
 
TimYatesCommented:
Ahhhh...

>>     if(verifypswdpolicy(pswd)){
>>         session.setAttribute("myvar","vrfied");                  

you're using the session

So page3 should be:

<%
  String value = (String)session.getAttribute("myvar");
   out.print("value : " + value);
%>
<meta http-equiv=Refresh content="5; url=http://<host>:<port>/PAGE3.jsp?mmyvar=<%=value%>">
0
 
myrizviAuthor Commented:
Thanks again Tim and sorry for last mistake.

Its working fine now.

BUT I dont want the value "vrfied" to be visible in the URL because anyone can use this URL to load the PAGE3
directly.

If you have any solution I will increase the points.

Thanks again.
0
 
TimYatesCommented:
Sorry, I'm a fool!

change

    <meta http-equiv=Refresh content="5; url=http://<host>:<port>/PAGE3.jsp?mmyvar=<%=value%>">

to

    <meta http-equiv=Refresh content="5; url=http://<host>:<port>/PAGE3.jsp">

you don't need it there any more, as it's in the session :-)

Tim
0
 
myrizviAuthor Commented:


Its working just fine.


You are not FOOL but COOOOOOOOOOOOOOOOOL.



Thanks again.
http://www.hyahya.org/

0
 
TimYatesCommented:
>> Its working just fine.

Yay!

>> You are not FOOL but COOOOOOOOOOOOOOOOOL.

hehehehe :-D

Glad you got it working!!

Good luck with it all!!

Tim
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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