Thoughts on alert () of JavaScript and response. sendredirect () of Java

Source: Internet
Author: User

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 !!

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.