Java Struts2 doubleselect实现省市级联下拉框

在Struts2中,给我们提供了一个s:doubleselect标签,该标签可以实现级联下拉选择。

doubleselect.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
	<title>Document</title>
	<%@ taglib prefix="s" uri="/struts-tags" %>
	<style type="text/css">select{width:200px;height:40px;}</style>
</head>
<body>
	<s:form action="resultAction" namespace="/">
	
		<s:bean name="top.k10000.DoubleSelectAction" id="location"></s:bean>
		
		<s:doubleselect 
			label="Server (OGNL) " 
			name="province" 
			list="#location.map.keySet()" 
			doubleName="city" 
			doubleList="#location.map[top]" />
			
		<s:submit value="submit" name="submit" />
	</s:form>
</body>
</html>

result.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
	<meta charset="utf-8">
	<title>Document</title>
</head>
<body>
	<s:property value="province"/> , <s:property value="city"/>
</body>
</html>

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>

	<constant name="struts.devMode" value="true" />
 	
	<package name="default" namespace="/" extends="struts-default">
		<action name="doubleSelectAction" class="top.k10000.DoubleSelectAction" method="display">
			<result name="success">/doubleselect.jsp</result>
		</action>
		
		<action name="resultAction" class="top.k10000.DoubleSelectAction">
			<result name="success">/result.jsp</result>
		</action>
  </package>
	
</struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name></display-name>	
  <welcome-file-list>
    <welcome-file>doubleselect.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>

DoubleSelectAction.java

package top.k10000;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;

public class DoubleSelectAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	private String province;
	private String city;
	Map<String, ArrayList<String>> map;

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Map<String, ArrayList<String>> getMap() {
		return map;
	}

	public void setMap(Map<String, ArrayList<String>> map) {
		this.map = map;
	}

	public DoubleSelectAction(){
		map =new HashMap<String, ArrayList<String>>();		
		map.put("广东省", new ArrayList<String>(Arrays.asList("广州市", "深圳市", "汕尾市","东莞市")));
		map.put("北京", new ArrayList<String>(Arrays.asList("东城区", "西城区","朝阳区")));
		map.put("新疆省", new ArrayList<String>(Arrays.asList("乌鲁木齐","克拉玛依市","图木舒克市")));
		System.out.println(map);
	}

	public String execute() {
		return SUCCESS;
	}
	
	public String display() {
		return SUCCESS;
	}
	
}



园子参考:https://www.cnblogs.com/IT-1994/p/6135952.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值