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.