一、前言
这段时间忙的要死,做项目,学框架,时间根本不够用,只能尽量抽出时间记录自己学过的东西。
1.1、doubleSelect
在之前学习中,我们使用过二级列表,相信很多人都理解其原理,在struts中,同样也为我们准备了二级列表,使用doubleSelect就能够时间
进入主题
1、搭建环境(这里笔者使用的struts框架是2.3的,传送门)
2、配置struts2.3环境
2.1、web.xml配置过滤器
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>LearStruts2_4</display-name> <welcome-file-list> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
2.2、在WEB-INF中新建class文件夹,文件夹下新建struts.xml配置信息
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <action name="doubleselectTag" class="com.struts.ui.action.DoubleSelectTagAction"> <result name="success">/doubleSelectTag.jsp</result> </action> </package> </struts>
3、新建实体类
package com.struts.ui.action; public class City { private int id; private String name; public City(){ } public City(int id,String name){ this.id = id; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }