Sample Code: JSP file
<% @ Page contenttype = "text/html; charset = gb2312" %>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> A prompt is displayed, and click OK to jump to a new address. </title>
</Head>
<Body>
<%
String url = request. getparameter ("url ");
String hasdays = request. getparameter ("hasdays ");
%>
<SCRIPT type = "text/JavaScript">
Alert ("system prompt: Your account is about to expire soon] [remaining" + <% = hasdays %> + "day ");
Window. Location. href = "<% = URL %> ";
</SCRIPT>
System prompt: Your account is about to expire soon !! Remaining <% = hasdays %> days;
<%
Response. sendredirect (URL );
%>
</Body>
</Html>
The above Code is expected to be implemented: First prompt the information about the upcoming expiration, and then click OK to jump to the address directed to response. sendredirect
However, the Java code embedded in JSP is executed on the server, so the execution effect of the above Code cannot meet the established functional assumptions.
Yes, no pop-up information will appear, and the response. sendredirect will be executed directly!
To implement the above function, we only use JavaScript to replace response. sendredirect to redirect the address. The Code is as follows:
<% @ Page contenttype = "text/html; charset = gb2312" %>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> A prompt is displayed, and click OK to jump to a new address. </title>
</Head>
<Body>
<%
String url = request. getparameter ("url ");
String hasdays = request. getparameter ("hasdays ");
%>
<SCRIPT type = "text/JavaScript">
Alert ("system prompt: Your account is about to expire soon] [remaining" + <% = hasdays %> + "day ");
Window. Location. href = "<% = URL %>"; <! -- JavaScript performs redirection instead of response. sendredirect -->
</SCRIPT>
System prompt: Your account will expire soon, remaining days <% = hasdays %>;
</Body>
</Html> OK !! Problem solved !!