Java code calling in jsp

Source: Internet
Author: User

There are two small exceptions when the original data is transmitted to the client:

1. If you want to transfer <% or %>, because it is consistent with the special symbols of jsp, you must use escape characters, <\ % or % \>
2. If you want to send comments, they will appear on the jsp editing page, but not in the generated html document, you need to use <% -- %>, and <! --> This form will be passed to the client intact.

Jsp calls dynamic code policies

Using mvc, a servlet processes the initial request, searches for data, stores the results in the bean, and forwards the request to the jsp page to submit the final result, the jsp page uses bean.

Java code location

Now jsp page java code volume, it is best to put some java code in the class, and then put the java class in WEB-INF/classes/directory/MachingPackageName, then use one or two lines of jsp-based code to call it. the reason is as follows:

1. for development, we generally write general classes (java) in the object-oriented development environment, and write jsp in the html-oriented environment, such as dreadweaver.
2. Compile. To compile a regular java class, compile it in the IDE. To compile a JSP page, you must put it in the correct directory and start the server.
3. debugging. IDE debugging in a separate environment is more convenient.
4. division of work, proficient in java only focus on java, proficient in html staff focus on html.
5. Test. You can test it separately.
6. Reuse. The same java class can be used on multiple jsp pages.

The package is very important, and all classes are placed at the guaranteed weight.

Use of jsp expressions

Jsp expressions are used to insert values directly into the output. <% = java expression %>

After the expression is evaluated and converted to a string, it is inserted into the page. The value is executed during running (when the page is requested), so all information of the request can be accessed.

Example: Current time: <% = new java. util. Date () %>

Predefined variables, request, reponse, session, out, application

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.