1 <%@ page language="java" contentType="text/html; charset=UTF-8"%> 2 <%@ taglib uri="/struts-tags" prefix="struts"%> 3 <%@ taglib uri="/struts-tags" prefix="s"%> 4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 5 <html> 6 <head> 7 <title>My JSP 'index.jsp' starting page</title> 8 <meta http-equiv="pragma" content="no-cache"> 9 <meta http-equiv="cache-control" content="no-cache"> 10 <meta http-equiv="expires" content="0"> 11 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 12 <meta http-equiv="description" content="This is my page"> 13 <!-- 14 <link rel="stylesheet" type="text/css" href="styles.css"> 15 --> 16 17 <struts:head theme="ajax" /> 18 19 <style type="text/css"> 20 body,td { 21 font-size: 12px; 22 } 23 </style> 24 </head> 25 26 <body> 27 28 <struts:fielderror></struts:fielderror> 29 30 <struts:form action="if"> <!-- 提交给"if.action" --> 31 <struts:textfield name="name" label="姓名: "></struts:textfield> 32 <struts:submit value=" 提交 "></struts:submit> 33 </struts:form> 34 35 <!-- 利用 request 参数判断 --> 36 <struts:if test="#parameters.name[0] == 'Kurt'"> <!-- 如果参数为Kurt --> 37 Hello, Kurt. 38 </struts:if> 39 <struts:elseif test="#parameters.name[0] == 'Matt'"> <!-- 如果参数为Matt --> 40 Hello, Matt. 41 </struts:elseif> 42 <struts:else> <!-- 否则 --> 43 Hello, Other Buddies. 44 </struts:else> 45 46 <br/> 47 48 <!-- 利用 action 属性判断 --> 49 <struts:if test="name == 'Kurt'"> 50 Hello, Kurt. 51 </struts:if> 52 <struts:elseif test="name == 'Matt'"> 53 Hello, Matt. 54 </struts:elseif> 55 <struts:else> 56 Hello, Other Buddies. 57 </struts:else> 58 59 <br/> 60 61 <!-- 62 <struts:set name="key" value="%{'You are welcome. '}"></struts:set> 63 <struts:property value="#key" /> <br/> 64 <struts:property value="%{#key}" /> <br/> 65 <struts:property value="key" /> <br/> 66 --> 67 68 69 </body> 70 </html>