JSP[3]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 lemonade 的 blog

<jsp:scriptlet>
code
</jsp:scriptlet>

4.3 jsp declarations

a jsp declaration lets you define methods or fields that get inserted into the main body of the servlet class (outside of the service method processing the request). it has the following form:
<%! java code %>
since declarations do not generate any output, they are normally used in conjunction with jsp expressions or scriptlets. for example, here is a jsp fragment that prints out the number of times the current page has been requested since the server booted (or the servlet class was changed and reloaded):
<%! private int accesscount = 0; %>
accesses to page since server reboot: 
<%= ++accesscount %>
as with scriptlets, if you want to use the characters "%>", enter "%\>" instead. finally, note that the xml equivalent of <%! code %> is
<jsp:declaration>
code
</jsp:declaration>

5. jsp directives

a jsp directive affects the overall structure of the servlet class. it usually has the following form:
<%@ directive attribute="value" %>
however, you can also combine multiple attribute settings for a single directive, as follows:
<%@ directive attribute1="value1" 
              attribute2="value2"
              ...
              attributen="valuen" %>
there are two main types of directive: page, which lets you do things like import classes, customize the servlet superclass, and the like; and include, which lets you insert a file into the servlet class at the time the jsp file is translated into a servlet. the specification also mentions the taglib directive, which is not supported in jsp version 1.0, but is intended to let jsp authors define their own tags. it is expected that this will be the main new contribution of jsp 1.1.

5.1 the jsp page directive

the page directive lets you define one or more of the following case-sensitive attributes:
  • import="package.class" or import="package.class1,...,package.classn". this lets you specify what packages should be imported. for example:
    <%@ page import="java.util.*" %>
    the import attribute is the only one that is allowed to appear multiple times.
  • contenttype="mime-type" or
    contenttype="mime-type; charset=character-set"
    this specifies the mime type of the output. the default is text/html. for example, the directive
    <%@ page contenttype="text/plain" %>
    has the same effect as the scriptlet

本文关键:JSP
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top