Details JSP expression
If you are direct use of Java servlets, then you will have to deal with HTTP input Java class and HTML output, you need a wealth of Java programming experience to build complex applications. JSP to join, so you can HTML presentation logic from the servlets in the implantation of the complex business logic separate. This means that can be experienced script writers to write the expression level code, and advanced Java developers can focus energy on solving servlets and bean in the more complex issues.
Whether you have Java programming knowledge, can use JSP.JSP contains some server-side tags, so Java code can not write a single line display dynamic data. You can directly access the bean to complete the operation, and then use the JSP label the results as dynamic content. You can also use servlets generated bean, servlets operation in which write the results and then display the results using the JSP label, also do not need to write Java code in JSP pages.
There are three ways your website can be used to add Java code:
1, using the declarations (statements), you can define global variables or in the pages can be accessed anywhere Java method. Statement be included in the tag < ;%! ... ...%> In.
2, using scriptlets (script fragment), you can write to any page within the processing logic necessary, they contain In “;% … …%> tags.
3, Expressions (expression), included in the < ;% = ... ...%> in. It provides an easy way to display the results of Java expressions. The expression to be added will be calculated and displayed on the page, as if you have clearly written in the code value as the result of the operation.
Write in your own code, you can use some hidden variables (implicit variables) - JSP Java provides predefined objects. In addition, through the use of JSP directives (directives), can also contain non-Java code modules, such as HTML text from other documents.
Here we take a closer look at the script element in the preparation of your own JSP script will always use them.
Directives (Directive)
JSP defines three pages in the JSP directive to set parameters or expand code. They are page, include and taglib, must be written on the first line of JSP pages. Syntax is as follows:
< ;% @ Directive attribute = "value" ... ...%>
Web page directive allows you to set some basic parameters, including the scripting language used to set the parameters (the default is Java), your script fragment introduced Java class, set the output buffer and so on. Complete parameter list, see page directive “JSP Specification Version 1.0″ (”JSP specification 1.0″) in Chapter 2.8.1.
Use include directive to include the contents of other documents, such as stored in a separate file in the HTML header and footer.
taglib directive for the expansion of the standard set of JSP tags, which goes beyond the scope of this article. However, the understanding of JSP defines a set of methods to expand its label is still very good, when you are a software vendor, would like to expand the JSP's original function but do not want to undermine its compatibility, this is especially important.
Declarations (Declaration)
Use declarations, you can define methods in JSP page or variable, they can be the same page with other code access. In most cases, you may define their own bean method. However, sometimes the web page definition method may be more convenient, especially when the code is used only for a single page. Regardless of method or variable definitions, declarations are included In “;%!%> Tags.
Note that the statement does not in the JSP page to generate any output. They are only used to define, without generating output. To generate output, you should use the JSP expression or script fragments.
Expressions (expression)
Expressions is a very simple JSP tag, which is used to In “;% =%> in the value of the expression defined in JSP and this value converted to string in the form of a dynamic text sent. Expression is really a shortcut to generate text, with it, you do not have a dynamic text to be displayed every time when they are to call the print () method. A typical application is that you can use a simple variable expressions show or bean in the return value.
In fact, prior to generating dynamic output, JSP must be the return value into a String object in Java. JSP specification describes in detail the expressions in JSP, what kind of Java types and Java classes will be transformed into a string.
Scriptlets (script fragment)
By now you have learned to use the command to the introduction of any Java class or Java package, you can define page-level method or variable, and use them in the page, you can also use the web to provide common processing functions of the hidden variables. Also in the JSP pages do depends on you, because you can scriptlets (script fragment) in writing any Java code you want
By using the IMPORT parameters page directive, you can be called from a script fragment all the Java API. For all JSP code you write is compiled in fact constitute a Java servlet, which in itself is a Java class, so you use the language itself is Java, rather than any modification or Consolidated version. It's like in SSJS in any code you can write the same. With SSJS different, you have the right to use the JSP package in a rich Java API, so almost no limitations.
Implicit Variables (hidden variables)
Mentioned earlier, JSP defines a number of hidden variables (ie, Java objects) for you to use expressions and script fragments. “JSP Specification Version 1.0″ of Table 2-2 lists the available JSP1.0 implicit variable. Here are some commonly used objects:
out the object of type javax.servlet.jsp.JspWriter, provides methods (such as print () method) access to the script fragments are generated output.
request directly with Java objects in the javax.servlet.http.HttpServletRequest class counterparts, with the object of the class of all properties and methods. HTML form or URL query string value passed in, you can call request.getParameter () method, under the name of access parameters.
response object and the corresponding Java class in the javax.servlet.http.HttpServletResponse provide your generated HTML page response parameters of the access. So, to return to the HTML in the JSP page to add a response header value, you can call the response.setHeader () methods to achieve.
We take a look at a form and its interaction between the JSP form handler process. Using the script element discussed earlier, I implemented a simple web site feedback form and a JSP form handler is used to validate input, and then conditionally generate an output based on feedback.
Button: submit query - submit; reset - re-fill
Handle the form name and comments will be field tested to determine if they have been filled, if any one or two are blank, the form handler will generate an error message; or whether it will continue to see the views of users and pre-set string matching. If matched, it outputs a specialized information; otherwise output “thank you”.
Recommended links:
runtime error 440 repair pc errors now
COREL KNOCKOUT Matting Examples Guide (6)
China's largest single-Rush biggest names in the computer upset falling by the wayside
Accounting Is The Common Language Of The Financial Sector
SEMICONDUCTOR India vied with New Deal
Simple MANAGEMENT And Distribution

When you can feel the things you want to feel able to say what you feel when this is a very happy time.
Comment by coach shoes — December 6, 2010 @ 8:37 am