struts2标签使用小结
[code]
1 #号,能访问actioncontext的上下文资源,例子如下:
public class OgnlAction extends ActionSupport implements ServletContextAware,
ServletRequestAware, SessionAware {
private static final long serialVersionUID = -6175904602786022346L;
private HttpServletRequest request;
private ServletContext application;
private Map session;
@SuppressWarnings("all")
private List magazineList = new ArrayList() {
{
add(new Magazine("时代周刊", 10));
add(new Magazine("足球之夜", 19));
add(new Magazine("时尚", 20));
add(new Magazine("时代影视", 50));
}
};
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public void setServletContext(ServletContext application) {
this.application = application;
}
@SuppressWarnings("all")
public void setSession(Map session) {
this.session = session;
}
public String execute() {
request.setAttribute("account", "account from request");
application.setAttribute("account", "account from response");
session.put("account", "account from session");
return Action.SUCCESS;
}
public List getMagazineList() {
return magazineList;
}
public void setMagazineList(List bookList) {
this.magazineList = bookList;
}
JSP页面:
所有的ID:
第一个ID:
request 中取属性:
session 中取属性:
application 中取属性:
attr 中取属性:
价格大于18元的杂志共有
- ¥ .
名称包含“时代”二字的杂志共有
- ¥ .
“足球之夜”的价格为 ¥
其中注意OGNL的灵活用法
2 下面两个注意区别:
其中第一个会输出字符串#request.account”,第二个会把request.account的结果输出.
3 autocomplete控件:
请选择国家:
其中href为获取数据的URL,indicator可以为一个属性或文字,获取数据的JSP如下:
out.clear();
request.setCharacterEncoding("UTF-8");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
String[] countries = { "。。。。。“}
String country = request.getParameter("country");
if (country == null)
country = "";
StringBuffer buffer = new StringBuffer();
for (int i = 0; i
4 连动框doubleselect:
provinceList = new ArrayList();
provinceList.add("北京");
provinceList.add("上海");
provinceList.add("天津");
provinceList.add("重庆");
provinceList.add("河北");
provinceList.add("河南");
provinceList.add("山东");
provinceList.add("山西");
provinceList.add("江苏");
provinceList.add("浙江");
request.setAttribute("provinceList", provinceList);
Map> cityMap = new HashMap>();
{
// 北京市
List cityList = new ArrayList();
cityList.add("东城区");
cityList.add("西城区");
cityList.add("海淀区");
cityList.add("朝阳区");
cityMap.put("北京", cityList);
}
{
// 山东省
List cityList = new ArrayList();
cityList.add("青岛");
cityList.add("济南");
cityList.add("潍坊");
cityList.add("烟台");
cityList.add("淄博");
cityMap.put("山东", cityList);
}
request.setAttribute("cityMap", cityMap);
%>
5 optiontransferselect标签
provinceSelected = new ArrayList();
provinceSelected.add("北京");
provinceSelected.add("上海");
provinceSelected.add("天津");
provinceSelected.add("重庆");
provinceSelected.add("河北");
provinceSelected.add("河南");
provinceSelected.add("山东");
provinceSelected.add("山西");
provinceSelected.add("江苏");
provinceSelected.add("浙江");
request.setAttribute("provinceSelected", provinceSelected);
List provinceUnselected = new ArrayList();
provinceUnselected.add("湖南");
provinceUnselected.add("湖北");
provinceUnselected.add("云南");
provinceUnselected.add("广东");
provinceUnselected.add("广西");
request.setAttribute("provinceUnselected", provinceUnselected);
%>
6 TAB标签
第一个 TabItem
第一个 TabItem
第二个 TabItem
第二个 TabItem
第一个 TabItem
第一个 TabItem
第二个 TabItem
第二个 TabItem
[/code]
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net