📄 jsp-actions.xtp
字号:
<s1 title="JSP Actions"><objsummary/><s2 name='lex' title='JSP Lexical'><defun name=jsp-escape title='escapes' index='escapes'><p>The JSP actions can be escaped using <var/<\%/>.</p><example><\% verbatim text %></example><results><% verbatim text %></results></defun><defun name=whitespace title='whitespace' index='whitespace' version='Resin 1.2'><p>JSP whitespace is copied to the output directly, unless escaped.</p><p>In Resin 1.2, if you place a backslash immediately after a JSP action andbefore a line end, Resin will omit the end of line. In the followingexample, Resin keeps the whitespace after the <var/<%@page ... %>/> andremoves it after after the <var/<%= 2 + 2 %>/>.</p><example><% @page session="true" %>a<%= 2 + 2 %>\c</example><results>a4c</results></defun></s2><s2 name='jsp' title='JSP Actions'><defun name=directive title='<%@ name att1="v1"... %>' index='directive'><p>Sets a JSP <a href='jsp-directives.xtp'>directive</a></p></defun><defun name=expr title='<%= expression %>' index='expression'><p>Prints the value of <var/expression/> evaluated the page's<a href='jsp-directives.xtp#language'>language</a>.</p><p>The expression action is equivalent to the following:</p><def> out.print(<var/expression/>);</def><p>It also has the following XML equivalent</p><def><jsp:expression> <var/expression/></jsp:expression></def><p>The following simple example just prints the value of a form variable.</p><example>Name: <%= request.getParameter("name") %></example><results>Name: George Washington</results></defun><defun name=scriptlet title='<% scriptlet %>' index='scriptlets'><p>Executes the statements in <var/scriptlet/> using the page's<a href='jsp-directives.xtp#language'>language</a>.</p><p>The <var/scriptlet/> is any statement list in the language,e.g. Java. The scriptlet can use any of the <ahref='jsp-variables.xtp'>implicit variables</a>, such as the requestobject and the out writer.</p><p>Scriptlets have the following XML equivalent</p><def><jsp:scriptlet> <var/scriptlet/></jsp:scriptlet></def><example><h1>Form results</h1><pre><% Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String key = e.nextElement(); String value = request.getParameter(key); out.println(key + ": " + value); }%></pre></example><results><h1>Form results</h1><pre> Name: George Washington Rank: General</pre></results></defun><defun name=decl title='<%! declaration %>' index='declaration'><p>Adds <var/declaration/> code to the Servlet class</p><p>JSP places the declaration code in the servlet class. In contrast,scriptlet and expression code are in a service method. Sodeclarations can declare class variables and methods.</p><note>Declarations are primarily useful for Java, but are allowed inJavaScript.</note><p>Declarations have the following XML equivalent</p><def><jsp:declaration> <var/declaration/></jsp:declaration></def><example><%= foo() %><%! private int foo() { return 1329; }%></example></defun><defun name=include title='<jsp:include page="path"/>' index='include, runtime'><p>Includes the contents of the local URL at <var/path/> duringruntime.</p><p>jsp:include is a runtime action. It will call the included<var/path/> just as if <var/path/> its own HTTP request. The resultof that page will be included in the current page.</p><p><var/path/> is relative to the current page. Its root is the rootof the application.</p><p>For compile-time includes, use <ahref='jsp-directives.xtp#include'><%@ include file='path'%></a></p><example title='inc.jsp'><%= 2 + 2 %></example><example title='test.jsp'>Header<jsp:include page='inc.jsp'/>Footer</example><results>Header4Footer</results></defun><defun name=forward title='<jsp:forward page="path" />' index='forward; redirect'><p>Forwards the request to another page, i.e. an internal redirect.</p><p>If the page has already written some output, jsp:request will clearthe output <a href='jsp-directives.xtp#buffer'>buffer</a>.</p><p><var/path/> is relative to the current page.</p><example title='fwd.jsp'><%= 2 + 2 %></example><example title='test.jsp'>Header<jsp:forward page='inc.jsp'/>Footer</example><results>4</results></defun><defun name=usebean title='<jsp:useBean id="name" ...>...' index='bean, creation'><p>Creates a new bean and variable for the page.</p><deftable><tr><th>Attribute<th>Value<th>Meaning<tr><td>id<td> <td>The variable name for the bean<tr><td>class<td> <td>The bean's Java class<tr><td>scope<td> <td> <tr><td> <td>page<td>Only active in the page, stored in pageContext<tr><td> <td>request<td>Active for the request, stored in request<tr><td> <td>session<td>Active for the session, stored in session<tr><td> <td>application<td>Active for the application, stored in application</deftable><p>jsp:useBean enables a popular style JSP page creation where JavaBeans calculate the content, and JSP formats the presentation.</p><p>jsp:useBean creates an initializes a JSP bean for the page. Thescope attribute determines the bean lifetime. For example, a sessionbean will be created once in a session.</p><p>jsp:useBean assigns the bean to the variable <var/name/>. It will alsostore the bean in the appropriate scope variable. For example, anapplication bean "foo" will be stored in the application variable.</p><p>jsp:useBean can also initialize beans. When jsp:useBean creates anew bean, it will execute the JSP in the jsp:useBean tag.</p><p>Roughly, JSP makes the following translation:</p><example><jsp:useBean id='foo' class='com.caucho.test.TestBean' scope='session'> <% foo.myInitialization("test"); %gt;</jsp:useBean></example><def>com.caucho.test.TestBean foo;foo = (com.caucho.test.TestBean) session.getValue("foo");if (foo == null) { foo = new com.caucho.test.TestBean(); session.value.foo = foo; foo.myInitialization("test");}</def></defun><defun name=getProperty title='<jsp:getProperty name="name" ... />' index='bean, display'><p>Prints a bean property.</p><deftable><tr><th>Attribute<th>Meaning<tr><td>name<td>The variable name for the bean<tr><td>property<td>The property name to retrieve.</deftable><p>jsp:getProperty converts property names following the beanstandards.</p><p>Roughly, jsp:getProperty makes the following conversion:</p><example><jsp:getProperty name='foo' property='bar'/></example><def>out.print(foo.getBar());</def></defun><defun name=setProperty title='<jsp:setProperty ... value="value"/>' index='bean, setting'><p>Sets a bean property to <var/value/>.</p><deftable><tr><th>Attribute<th>Meaning<tr><td>name<td>The variable name for the bean<tr><td>property<td>The property name to set.<tr><td>value<td>The value to set.</deftable><p>If value is a runtime attribute, the bean property gets theexpression value. If it's a static string, the value is firstconverted to the argument type and then set.</p><example><jsp:setProperty name='foo' property='count' value='10'/></example><results>foo.setCount(10);</results><example><jsp:setProperty name='foo' property='string' value='10'/></example><results>foo.setString("10");</results><example><jsp:setProperty name='foo' property='count' value='<%= 2 + 2 %>'/></example><results>foo.setCount(2 + 2);</results><example><jsp:setProperty name='foo' property='count' value='2 + 2'/></example><results>error</results><example><jsp:setProperty name='foo' property='char' value='10'/></example><results>foo.setChar('1');</results></defun><defun name=setProperty title='<jsp:setProperty ... param="param"/>' index='bean, setting'><p>Sets a bean property to a parameter value.</p><deftable><tr><th>Attribute<th>Value<th>Meaning<tr><td>name<td> <td>The variable name for the bean<tr><td>property<td><var/property/><td>The property name to set.<tr><td> <td>*<td>Set all properties<tr><td>param<td><var/param/><td>The form parameter to use as a value.<tr><td> <td><var/empty/><td>If missing, use <var/property/></deftable><p>The second form of jsp:setProperty lets scripts easily set Beanproperties to form values.</p></defun></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -