EL标签的简单应用

在MyEclipse 下 Web Project 简单EL标签的使用:

在 Struts 框架下:

Test_EL.java

package com.classes;

public class Test_EL {
	private  String username;
	private  String password;
	private  int age;
	private  String sex;
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}

}

 

TestForm.java

package com.el.struts.form;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class TestForm extends ActionForm {
	
	private String username;
	private String password;
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		// TODO Auto-generated method stub
		return null;
	}
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		// TODO Auto-generated method stub
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}	
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
}

 

TestAction.java

package com.el.struts.action;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.classes.Test_EL;
import com.el.struts.form.TestForm;

public class TestAction extends Action {	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		TestForm testForm = (TestForm) form;// TODO Auto-generated method stub		
		request.setAttribute("name", "name_zhao");
		Test_EL test_el=new Test_EL();
		test_el.setUsername("zhao");
		test_el.setPassword("password1");
		test_el.setAge(1);
		test_el.setSex("男");
		Test_EL test_e=new Test_EL();
		test_e.setUsername("zhao");
		test_e.setPassword("password1");
		test_e.setAge(2);
		test_e.setSex("女");
		request.getSession().setAttribute("test_el",test_el);
		List list=new ArrayList();
		list.add(test_el);
		list.add(test_e);
		request.setAttribute("list", list);		
		return mapping.findForward("test11");
	}
}

 test.jsp

<%@ page language="java"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> 
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>

<!--  jsp:useBean id="test_el" scope="page" class="com.classes.Test_EL"/-->


<html> 
	<head>
		<title>JSP for TestForm form</title>
	</head>
	<body>
		<html:form action="test">
			username : <html:text property="username"/><html:errors property="username"/><br/>
			password : <html:password property="password"/><html:errors property="password"/><br/>
			<html:submit/><html:cancel/>
		</html:form>
		<table>
		
		  <tr>
		     <td>
		        ${test_el.username}
		     </td>
		  </tr>
		  <tr>
		     <td>
		        ${test_el.password}
		     </td>
		  </tr>
		  <tr>
		     <td>
		        ${test_el.age}
		     </td>
		  </tr>
		  <tr>
		     <td>
		        ${test_el.sex}
		     </td>
		  </tr>
		  <tr>
		     <td>
		     <c:if test="${name!=null}" var="t">
		        wo shi shi wo !		       
		     </c:if>
		     </td>
		  </tr>
		  <tr>
		     <td>
		     <c:forEach items="${list}" var="tag" varStatus="id">
		          ${id.count} ++${tag.username }++aaaa<br>
		          ${id.index} ++${tag.password }++aaaa<br>
		          ${id.first} ++${tag.age }++aaaa<br>
		          ${id.last} ++${tag.sex }++aaaa<br>
		     </c:forEach>
		     </td>
		  </tr>
		  <tr>
		    <td>
		       <c:out value="name_cou"></c:out>
		    </td>
		  </tr>
		</table>
	</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值