Ubuntu开发Struts2应用(3、知识点记录)

2012年01月16日 JAVA, Linux, Ubuntu 暂无评论
 
 
本节记录了一些struts2的知识点。

1、设置开发调试
struts.properties
struts.devMode = true
添加struts2-config-browser-plugin-2.3.1.jar
地址访问:http://localhost:8080/struts2T1/config-browser/index.action
使用标签<s:debug/>显示
地址访问:
http://localhost:8080/struts2/linuxsight.action?debug=xml
http://localhost:8080/struts2/linuxsight.action?debug=console
2、在struts.properties更换struts2默认主题
struts.ui.theme=simple//主题设为simple,不会在生成多余的html代码
3、struts2运行时变量查找顺序
default.properties
struts-plugin.xml
struts.xml
struts.properties
web.xml
4、关于web.xml加入的struts2过滤器
struts2.1.3之后使用StrutsPrepareAndExecuteFilter
而org.apache.struts2.dispatcher.FilterDispatcher已经过时
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
5、在struts.xml中action的各项默认值
<action name="hello" method="execute">
<result name="success">/WEB-INF/jsp/hello.jsp</result>
</action>
Action配置中的各项默认值
class  ActionSupport
method  execute
result name属性 success
6、实现struts1的DispatchAction
使用通配符定义
<action name="user_*" method="{1}">
<result name="success">/WEB-INF/jsp/success.jsp</result>
</action>
7、属性范围获取
ActionContext ctx=ActionContext.getContext();
ctx.getApplication().put("application", "application范围");
ctx.getSession().put("session", "session范围");
ctx.put("request", "request范围");
HttpServletRequest request=ServletActionContext.getRequest();
ServletContext servletContext=ServletActionContext.getServletContext();
HttpSession session=request.getSession();
request.setAttribute("request", "request范围");
session.setAttribute("session", "session范围");
servletContext.setAttribute("application", "application范围");
8、一些标签的使用
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>struts2标签使用</title>
</head>
<body>
<h3>集合迭代</h3>
<s:set name="list" value="{'ubuntu','fedora','opensuse','mandriva','slackware','gentoo','archlinux'}" />
<s:iterator value="#list" status="linux">
<font color=<s:if test="#linux.odd">red</s:if><s:else>blue</s:else> >
<s:property />
</font><br/>
</s:iterator>
<hr/>
<h3>list复选框</h3>
<s:checkboxlist name="list" list="{'windows','linux','mac','bsd','solaris'}" value="{'linux','mac'}" />
<hr/>
<h3>map复选框</h3>
<s:checkboxlist name="map" list="#{1:'android',2:'ios',3:'symbian',4:'wp7',5:'blackberry'}"
listKey="key" listValue="value" value="{1,2,4}" />
<hr/>
<h3>集字符串类型处理</h3> <br>
<s:set name="url" value="'http://www.linuxsight.com'"/>
<s:url value="%{#url}" />
<hr/>
<h3>单选框</h3>
 <s:radio name="raido" list="#{1:'塞班',2:'微软',3:'黑莓',4:'苹果',5:'安卓'}" listKey="key" listValue="value" value="1"/>
 <br/>
<h3>下拉框</h3>
<s:select name="select" list="#{1:'电脑',2:'手机',3:'系统',4:'网站'}" listKey="key" listValue="value" value="1"/>
</body>
</html>

Ubuntu开发Struts2应用(3、知识点记录)

给我留言