JavaScript alert () and Java response.sendredirect () Experience thinking __java

Source: Internet
Author: User

Sample code: JSP file <% @ page contenttype = "text/html; charset=gb2312"%>
< HTML >
< Head >
< META&NBSP;HTTP-EQUIV = "Content-type"  content = "text/html; charset=gb2312" >
< title > First pop-up message, then click OK to jump to the new address </title >
< the body >
<%
&NBSP;&NB Sp; string url = request.getparameter ("url");
   string hasdays = Request.getparameter ("Hasdays");
%>
< Script type = "Text/javascript" >
   alert ("system hint: your account is about to expire] [remaining" +&L t;%= hasdays%>+ "Days");
   window.location.href = "<%=url%>";
</script >
System tip: Your account is about to expire!! Remaining <%= hasdays%> days;
<%
   response.sendred Irect (URL);
%>
</body >
</HTML >

Originally hope that the above code implementation: first prompt will expire information, then click OK to jump to response.sendredirect point of address
However, because the Java code embedded in the JSP is executed on the server side, the execution effect of the above code can not satisfy the established function assumption,
There is no pop-up message, and the response.sendredirect! is executed directly.
In order to realize the above functions, we can only use JavaScript instead of Response.sendredirect to complete the address of the jump, the code is as follows:
<% @ Page ContentType = "text/html; charset=gb2312 "%>
< HTML >
< head >
< meta HTTP-EQUIV = "Content-type" Content = "text/html"; charset=gb2312 ">
< title > First pop-up message, then click OK and then jump to the new address </title >
< BODY >
<%
String url = request.getparameter ("url");
String hasdays = Request.getparameter ("Hasdays");
%>
< script type = "Text/javascript" >
Alert ("System hint: your account is about to expire] [remaining" +<%= hasdays%>+ "Day");
Window.location.href = "<%=url%>"; <!--JavaScript instead of Response.sendredirect do jump-->
</script >
System tip: Your account is about to expire, the remaining <%= hasdays%> days;
</Body >
</HTML >
Ok!! The problem is solved!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.