⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 struts 2中的ognl - max on java - blogjava.htm

📁 struts2标签的详细解释说明教程
💻 HTM
📖 第 1 页 / 共 5 页
字号:
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #000000">struts-cleanup</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">filter-name</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">url-pattern</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/*</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">url-pattern</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">filter-mapping</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; 
&nbsp;&nbsp;<BR>&nbsp; &nbsp; </SPAN><SPAN 
style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">filter</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">filter-name</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #000000">struts2</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">filter-name</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">filter-class</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; 
org.apache.struts2.dispatcher.FilterDispatcher<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">filter-class</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">filter</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><BR>&nbsp; 
&nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">filter-mapping</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">filter-name</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #000000">struts2</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">filter-name</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">url-pattern</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">/*</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">url-pattern</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">filter-mapping</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><BR>&nbsp; 
&nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">welcome-file-list</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
&nbsp; &nbsp; </SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN 
style="COLOR: #800000">welcome-file</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #000000">index.html</SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">welcome-file</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp; &nbsp; 
</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">welcome-file-list</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN><SPAN 
style="COLOR: #000000"><BR><BR></SPAN><SPAN 
style="COLOR: #0000ff">&lt;/</SPAN><SPAN 
style="COLOR: #800000">web-app</SPAN><SPAN 
style="COLOR: #0000ff">&gt;</SPAN></DIV><SPAN 
style="FONT-SIZE: smaller; FONT-STYLE: italic">清单1 
WebContent/WEB-INF/web.xml</SPAN> 
<P>“#”主要有三种用途:</P>
<OL>
  <LI>访问OGNL上下文和Action上下文,#相当于ActionContext.getContext();下表有几个ActionContext中有用的属性: 

  <TABLE style="BORDER-TOP: #008000 2px solid; BORDER-BOTTOM: #008000 2px solid" 
  cellSpacing=0 cellPadding=2 border=0>
    <TBODY>
    <TR>
      <TD 
      style="FONT-WEIGHT: bold; BORDER-BOTTOM: #008000 1px solid; HEIGHT: 21px; BACKGROUND-COLOR: #ccffcc">&nbsp;名称</TD>
      <TD 
      style="FONT-WEIGHT: bold; BORDER-BOTTOM: #008000 1px solid; HEIGHT: 21px; BACKGROUND-COLOR: #ccffcc">作用</TD>
      <TD 
      style="FONT-WEIGHT: bold; BORDER-BOTTOM: #008000 1px solid; HEIGHT: 21px; BACKGROUND-COLOR: #ccffcc">例子</TD></TR>
    <TR>
      <TD>parameters</TD>
      <TD>包含当前HTTP请求参数的Map</TD>
      <TD>#parameters.id[0]作用相当于request.getParameter("id")</TD></TR>
    <TR>
      <TD>request</TD>
      <TD>包含当前HttpServletRequest的属性(attribute)的Map</TD>
      <TD>#request.userName相当于request.getAttribute("userName")</TD></TR>
    <TR>
      <TD>session</TD>
      <TD>包含当前HttpSession的属性(attribute)的Map</TD>
      <TD>#session.userName相当于session.getAttribute("userName")</TD></TR>
    <TR>
      <TD>application</TD>
      <TD>包含当前应用的ServletContext的属性(attribute)的Map</TD>
      <TD>#application.userName相当于application.getAttribute("userName")</TD></TR>
    <TR>
      <TD>attr</TD>
      <TD>用于按request &gt; session &gt; application顺序访问其属性(attribute)</TD>
      <TD>#attr.userName相当于按顺序在以上三个范围(scope)内读取userName属性,直到找到为止</TD></TR></TBODY></TABLE>
  <LI>用于过滤和投影(projecting)集合,如<SPAN 
  style="BACKGROUND-COLOR: lightgrey">books.{?#this.price&lt;100}</SPAN>; 
  <LI>构造Map,如<SPAN style="BACKGROUND-COLOR: lightgrey">#{'foo1':'bar1', 
  'foo2':'bar2'}</SPAN>。 </LI></OL>
<P>下面让我们它们的具体写法,首先是Action类代码:</P>
<DIV 
style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" align=top><SPAN 
style="COLOR: #0000ff">package</SPAN><SPAN style="COLOR: #000000"> 
tutorial.action;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> java.util.LinkedList;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> java.util.List;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> java.util.Map;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> javax.servlet.ServletContext;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> javax.servlet.http.HttpServletRequest;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> 
org.apache.struts2.interceptor.ServletRequestAware;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> org.apache.struts2.interceptor.SessionAware;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> org.apache.struts2.util.ServletContextAware;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> tutorial.model.Book;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">import</SPAN><SPAN 
style="COLOR: #000000"> com.opensymphony.xwork2.ActionSupport;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/None.gif" align=top><BR><IMG 
id=Codehighlighter1_538_1855_Open_Image 
onclick="this.style.display='none'; Codehighlighter1_538_1855_Open_Text.style.display='none'; Codehighlighter1_538_1855_Closed_Image.style.display='inline'; Codehighlighter1_538_1855_Closed_Text.style.display='inline';" 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/ExpandedBlockStart.gif" 
align=top><IMG id=Codehighlighter1_538_1855_Closed_Image style="DISPLAY: none" 
onclick="this.style.display='none'; Codehighlighter1_538_1855_Closed_Text.style.display='none'; Codehighlighter1_538_1855_Open_Image.style.display='inline'; Codehighlighter1_538_1855_Open_Text.style.display='inline';" 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/ContractedBlock.gif" 
align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN 
style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN 
style="COLOR: #000000"> OgnlAction </SPAN><SPAN 
style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000"> ActionSupport 
</SPAN><SPAN style="COLOR: #0000ff">implements</SPAN><SPAN 
style="COLOR: #000000"> ServletRequestAware, SessionAware, ServletContextAware 
&nbsp;</SPAN><SPAN id=Codehighlighter1_538_1855_Closed_Text 
style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/dot.gif"></SPAN><SPAN 
id=Codehighlighter1_538_1855_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN 
style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN 
style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">long</SPAN><SPAN 
style="COLOR: #000000"> serialVersionUID </SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN 
style="COLOR: #000000">1L</SPAN><SPAN style="COLOR: #000000">;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000"> HttpServletRequest request;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000"> Map</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN 
style="COLOR: #000000">String, String</SPAN><SPAN 
style="COLOR: #000000">&gt;</SPAN><SPAN style="COLOR: #000000"> session;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN 
style="COLOR: #000000"> ServletContext application;<BR><IMG 
src="Struts 2中的OGNL - Max On Java - BlogJava.files/InBlock.gif" align=top> 
&nbsp; &nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -