📄 jsp-actions.xtp
字号:
<document> <header> <product>resin</product> <title>Actions</title> <description type="brief"> <p> Actions are the core of JSP. Actions range from printing a script expression, to creating and storing a Java Bean. </p> </description> </header> <body><summary/><s1 name="lex" title="JSP Lexical"><s2 name="jsp-escape" title="escapes" index="escapes" type="defun"><p>The JSP actions can be escaped using <var><\%</var>.</p><example><\% verbatim text %></example><results><% verbatim text %></results></s2><s2 name="whitespace" title="whitespace" index="whitespace" version="Resin 1.2" type="defun"><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 ... %></var> andremoves it after after the <var><%= 2 + 2 %></var>.</p><example><% @page session="true" %>a<%= 2 + 2 %>\c</example><results>a4c</results></s2></s1><s1 name="jsp" title="JSP Actions"><s2 name="directive" title="<%@ name att1="v1"... %>" index="directive" type="defun"><p>Sets a JSP <a href="jsp-directives.xtp">directive</a></p></s2><s2 name="expr" title="<%= expression %>" index="expression" type="defun"><p>Prints the value of <var>expression</var> 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</var>);</def><p>It also has the following XML equivalent</p><def><jsp:expression> <var>expression</var></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></s2><s2 name="scriptlet" title="<% scriptlet %>" index="scriptlets" type="defun"><p>Executes the statements in <var>scriptlet</var> using the page's<a href="jsp-directives.xtp#language">language</a>.</p><p>The <var>scriptlet</var> is any statement list in the language,e.g. Java. The scriptlet can use any of the <a href="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</var></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></s2><s2 name="decl" title="<%! declaration %>" index="declaration" type="defun"><p>Adds <var>declaration</var> 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</var></jsp:declaration></def><example><%= foo() %><%! private int foo() { return 1329; }%></example></s2><s2 name="include" title="<jsp:include page="path"/>" index="include, runtime" type="defun"><p>Includes the contents of the local URL at <var>path</var> duringruntime.</p><p>jsp:include is a runtime action. It will call the included<var>path</var> just as if <var>path</var> its own HTTP request. The resultof that page will be included in the current page.</p><p><var>path</var> is relative to the current page. Its root is the rootof the application.</p><p>For compile-time includes, use <a href="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></s2><s2 name="forward" title="<jsp:forward page="path" />" index="forward; redirect" type="defun"><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</var> 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></s2><s2 name="usebean" title="<jsp:useBean id="name" ...>..." index="bean, creation" type="defun"><p>Creates a new bean and variable for the page.</p><deftable><tr><th>Attribute</th><th>Value</th><th>Meaning</th></tr><tr><td>id</td><td> </td><td>The variable name for the bean</td></tr><tr><td>class</td><td> </td><td>The bean's Java class</td></tr><tr><td>scope</td><td> </td><td> </td></tr><tr><td> </td><td>page</td><td>Only active in the page, stored in pageContext</td></tr><tr><td> </td><td>request</td><td>Active for the request, stored in request</td></tr><tr><td> </td><td>session</td><td>Active for the session, stored in session</td></tr><tr><td> </td><td>application</td><td>Active for the application, stored in application</td></tr></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</var>. 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></s2><s2 name="getProperty" title="<jsp:getProperty name="name" ... />" index="bean, display" type="defun"><p>Prints a bean property.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>name</td><td>The variable name for the bean</td></tr><tr><td>property</td><td>The property name to retrieve.</td></tr></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></s2><s2 name="setPropertyValue" title="<jsp:setProperty ... value="value"/>" index="bean, setting" type="defun"><p>Sets a bean property to <var>value</var>.</p><deftable><tr><th>Attribute</th><th>Meaning</th></tr><tr><td>name</td><td>The variable name for the bean</td></tr><tr><td>property</td><td>The property name to set.</td></tr><tr><td>value</td><td>The value to set.</td></tr></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></s2><s2 name="setPropertyParam" title="<jsp:setProperty ... param="param"/>" index="bean, setting" type="defun"><p>Sets a bean property to a parameter value.</p><deftable><tr><th>Attribute</th><th>Value</th><th>Meaning</th></tr><tr><td>name</td><td> </td><td>The variable name for the bean</td></tr><tr><td>property</td><td><var>property</var></td><td>The property name to set.</td></tr><tr><td> </td><td>*</td><td>Set all properties</td></tr><tr><td>param</td><td><var>param</var></td><td>The form parameter to use as a value.</td></tr><tr><td> </td><td><var>empty</var></td><td>If missing, use <var>property</var></td></tr></deftable><p>The second form of jsp:setProperty lets scripts easily set Beanproperties to form values.</p></s2></s1> </body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -