What is the better way to use the output in a JSP? __jsp

Source: Internet
Author: User
question: Which output method is better in JSP. You've learned how to use OUT.PRINTLN () and <%=%> output, so which output is better in development.
Answer:

In the development of JSP, is actually in the HTML to add some control and output statements, so in the output in order to make the HTML code and Java code separation, the best way is to output only the right JSP generated variables, then use the expression output than using the OUT.PRINTLN () More convenient.


before you explain the advantages of both, take a look at a topic: "The multiplication formula within the output 10", and the following is done with Out.println () and an expression. use OUT.PRINTLN () output:

<%@ page contenttype= "Text/html;charset=utf-8"%>

Analysis: Such output can cause code confusion, because the HTML and Java code tightly coupled together, later debugging can be cumbersome, so the best thing to do is to separate the HTML code and Java code. use <%=%> expression output:

<%@ page contenttype= "Text/html;charset=utf-8"%>

Analysis: This kind of program code is very good to the HTML code and Java code separation, such code will later use similar to Dreamweaver such as web design tool adjustment is also very convenient.

However, some readers may think that the above code is too complicated, to write a lot of scriptlet code, seems to be a bit messy, here I give readers such a suggestion: "Must acknowledge the above code to write, in the future study will be the code for the continuous optimization, make it easier to read, must remember , you must never use OUT.PRINTLN () for output. ”

And in the above code writing, if a For statement is written in more than one scriptlet, be sure to write "{}", otherwise the program will appear an error.

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.