struts-标签的使用(二)
2017-08-20 15:57
225 查看
<%@page import="po.Student,java.util.*"%> <%@ page language="java" pageEncoding="UTF-8"%> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html lang="true"> <head> <title>MyJsp.jsp</title> </head> <body> 这是第一个页面 <a href="jsp2.jsp">链接1</a><br> <html:link page="/jsp2.jsp">链接2</html:link><br> <html:link href="jsp2.jsp">链接3</html:link><br> <html:link forward="JSP2">链接4</html:link> <html:link action="/xxx.do">链接5(适合链接的同时还作一些操作的情况)</html:link> <hr> <html:link page="/jsp2.jsp?param=0001">到达jsp2,传参数1</html:link><br> <% request.setAttribute("msg", "<b>0001</b>"); // Student stu=new Student(); stu.setUserID("0001"); session.setAttribute("stu", stu); //多个参数可以放入HashMao HashMap<String,String> hm=new HashMap<String,String>(); hm.put("param1", "msg1"); hm.put("param2", "msg2"); hm.put("param3", "msg3"); session.setAttribute("paramList", hm); Cookie c=new Cookie("username","Kate"); c.setMaxAge(1000*60); response.addCookie(c); %> <html:link page="/jsp2.jsp" paramId="param" paramName="msg" >到达jsp2,传参数2</html:link><br> <html:link page="/jsp2.jsp" paramName="stu" paramId="param" paramProperty="userID"></html:link> <html:link page="/jsp2.jsp" name="paramList" >到达jsp2,传参数3</html:link> </body> </html:html>
<%@page import="po.Student" %> <%@ page language="java" pageEncoding="UTF-8"%> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html lang="true"> <head> <title>jsp2.jsp</title> </head> <body> 获得参数param:<%=request.getParameter("param") %><br> 获得参数param: <bean:parameter name="param" id="str"/> <bean:write name="str" filter="false"/><br> 显示JavaBean内的属性(stu从session内得到):<bean:write name="stu" property="userID"/> Cookie的值:<bean:cookie name="username" id="cookie1"/><bean:write name="cookie1" property="value"/> <!-- 判断str是否等于0001,是就显示"OK" --> <logic:equal name="str" value="0001"> OK </logic:equal> </body> </html:html>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<%@ page language="java" pageEncoding="UTF-8"%> <%@page import="java.util.*,po.Student" %> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitiona 4000 l//EN"> <html:html lang="true"> <head> <html:base /> <title>jsp3.jsp</title> </head> <body> 这是第三个页面<br> <html:link href="jsp4.jsp">跳转到页面4</html:link> <% //简单集合:集合(数组)里面是i暗淡数据 ArrayList<String> books=new ArrayList<String>(); books.add("三国演义"); books.add("水浒传"); books.add("西游记"); session.setAttribute("books", books); //集合里面含有 JavaBean ArrayList<Student> stus=new ArrayList<Student>(); Student stu1=new Student(); stu1.setUserID("0001"); Student stu2=new Student(); stu2.setUserID("0002"); Student stu3=new Student(); stu3.setUserID("0003"); stus.add(stu1); stus.add(stu2); stus.add(stu3); session.setAttribute("stus", stus); //javaBean里面有集合 Student stu4=new Student(); ArrayList phones=new ArrayList(); phones.add("123123"); phones.add("34534543"); stu4.setPhone(phones); session.setAttribute("stu4", stu4); //复杂契合:以HashMap为代表 HashMap<String,String> hm=new HashMap<String,String>(); hm.put("param1", "msg1"); hm.put("param2", "msg2"); hm.put("param3", "msg3"); session.setAttribute("hm", hm); %> </body> </html:html>
<%@ page language="java" pageEncoding="UTF-8"%> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html lang="true"> <head> <title>jsp4.jsp</title> </head> <body> 这是第四个页面<br> 简单集合: <logic:iterate id="book" name="books"> <bean:write name="book"/> </logic:iterate><hr> 集合里面含有javaBean <logic:iterate id="stu" name="stus"> <bean:write name="stu" property="userID"/> </logic:iterate><br> JavaBean里有集合: <logic:iterate id="stu_phones" name="stu4" property="phone"> <bean:write name="stu_phones"/> </logic:iterate><br> 遍历HashMap: <logic:iterate id="hm_key" name="hm"> <bean:write name="hm_key" property="value"/> </logic:iterate> </body> </html:html>
相关文章推荐
- Struts Html:Checkbox 标签使用技巧
- struts中logic:iterator标签的使用
- struts2.1.6教程六、使用标签
- 在使用struts标签的时候最好加上theme="simple"
- JSTL、EL、ONGL、Struts标签的区别与使用
- 求一跨页提交的例子,尽量使用jsp+js+struts1(别用struts标签)开发出来的例子 ,该怎么处理
- struts 迭代器iterator四种使用方式 S标签
- struts2.1.6s:datetimepicker标签不能使用的问题解决(转载)
- Struts使用标签的问题
- Struts -- html:link 标签的使用
- struts 标签 HTML:MESSAGES 使用范例
- struts中logic:iterator标签的使用
- struts 标签logic:match 使用注意事项
- 【转】使用Struts标签的基本配置
- struts标签<s:date>的使用
- 关于如何使用struts标签输出值为map的list
- 4-Struts标签的使用--logic(empty, notEmpty, present, notPresent)
- 【struts】——bean_write标签使用
- [struts2学习笔记] 第四节 学着使用struts 2的tag标签
- struts中ec标签的使用【转】