Java scripts in the JSP JSP

Source: Internet
Author: User

Foreword in modern web development, embedding Java script in JSP is not recommended, because it is not conducive to the maintenance of code. There are a number of good, alternative ways to avoid writing Java scripts in the JSP. This article is only an understanding of JSP system technology. class member Definitions1. Put the defined code in the <%! Between%>. The members that are defined are converted to members of the Servlet class. 2. You can define any member method and member fields, either static members or instance members. 3, note that Jsp/servlet is working in a multi-threaded environment, the definition of member variables to pay attention to thread safety issues.  It is generally recommended to use local variables in the _jspservice method. <%@ page contenttype= "text/html; Charset=utf-8 "pageencoding =" UTF-8 "trimdirectivewhitespaces =" true "session=" true "%><%!Public void Jspinit (){System.out.println ("JSP initialization work: Jspinit");} Public void Jspdestroy (){System.out.println ("JSP cleanup work: Jspdestroy");} private Final int a = +; %><! DOCTYPE Html> Small Script Fragment1, the definition of small script using <%%>2, the Java code in the small script will be inserted into the _jspservice method, where it is defined, in order to insert there. <%@ page contenttype= "text/html; Charset=utf-8 "pageencoding =" UTF-8 "trimdirectivewhitespaces=" true "session =" true "%> <! DOCTYPE html><% int a = 100+10;out.print ("100+10=" +a + "<br/>");out.print ("La la la la la");%></body>

Expression Script1. <%= expression%>, note the end of the expression do not semicolon. 2. Used to get a string literal representation of a Java variable (object). The default is to call the object's ToString method to get <! DOCTYPE Html>

Java scripts in the JSP JSP

Related Article

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.