1 package MyTrain01; 2 3 public class CheckAction { 4 String []hobbies; 5 6 public String[] getHobbies() { 7 8 return hobbies; 9 } 10 11 public void setHobbies(String[] hobbies) { 12 this.hobbies = hobbies; 13 } 14 15 public String execute(){ 16 return "success"; 17 } 18 }
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ taglib prefix="s" uri="/struts-tags" %> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Insert title here</title> 9 </head> 10 <body> 11 <s:form method="post" action="/test01/check.action"> 12 <s:checkbox label="阅读" name="hobbies" fieldValue="阅读"></s:checkbox> 13 <s:checkbox label="音乐" name="hobbies" fieldValue="音乐"></s:checkbox> 14 <s:checkbox label="旅游" name="hobbies" fieldValue="旅游"></s:checkbox> 15 <s:checkbox label="绘画" name="hobbies" fieldValue="绘画"></s:checkbox> 16 <s:checkbox label="书法" name="hobbies" fieldValue="书法"></s:checkbox> 17 <s:submit value="提交"/> 18 </s:form> 19 </body> 20 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Insert title here</title> 9 </head> 10 <body> 11 <c:forEach items="${hobbies }" var="ho"> 12 ${ho } 13 </c:forEach> 14 </body> 15 </html>
1 <?xml version="1.0" encoding="UTF-8" ?> 2 3 <!DOCTYPE struts PUBLIC 4 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 5 "http://struts.apache.org/dtds/struts-2.0.dtd"> 6 <struts> 7 <package name="test01" namespace="/test01" extends="struts-default"> 8 <action name="login_*" class="MyTrain01.LoginAction" method="{1}"> 9 <result name="success">/User/success.jsp</result> 10 <result name="error">/User/success.jsp</result> 11 </action> 12 <action name="check" class="MyTrain01.CheckAction" method="execute"> 13 <result name="success">/testCheck.jsp</result> 14 </action> 15 </package> 16 </struts>
时间: 2024-10-01 03:21:25