Drop down menu 3个或更多使用struts2的相关下拉列表

Drop down menu 3个或更多使用struts2的相关下拉列表,drop-down-menu,combobox,Drop Down Menu,Combobox,我正在尝试不同的方法来制作4个相关下拉列表。通过选择第一个,填充2,在选择第二个popluate第三个下拉列表时,以及在选择第三个下拉列表时,获得第四个下拉列表的项目列表 在进行研究时,我发现这一点与我的想法非常接近。这是正常的jsp和ajax使用。我正在寻找一个基于struts2的列表,而且这个示例使用多个页面来获取列表。每个列表都基于不同的jsp页面 struts2 double-select工作得很好,但它仅限于两个下拉列表。无论如何,我们都可以将其扩展到更多或更多的教程或帮助。非常感谢。

我正在尝试不同的方法来制作4个相关下拉列表。通过选择第一个,填充2,在选择第二个popluate第三个下拉列表时,以及在选择第三个下拉列表时,获得第四个下拉列表的项目列表

在进行研究时,我发现这一点与我的想法非常接近。这是正常的jsp和ajax使用。我正在寻找一个基于struts2的列表,而且这个示例使用多个页面来获取列表。每个列表都基于不同的jsp页面


struts2 double-select工作得很好,但它仅限于两个下拉列表。无论如何,我们都可以将其扩展到更多或更多的教程或帮助。非常感谢。

Struts2 Jquery有助于解决此问题。但谷歌提供的帮助不多,教程完成了一半。我认为这对其他任何想在项目中实施的人都是有用的。因此在下面分享它。我将尝试上传这个war文件并在这里共享链接

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_9" version="2.4">
  <display-name>Struts2 Application</display-name>
  <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>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

getJson()方法只调用execute()有什么意义?这只是一种形式来确保json插件在特定操作上被调用,还是所有json类型结果都需要这样做?
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />
    <constant name="struts.custom.i18n.resources" value="ApplicationResources" />

    <package name="default" extends="json-default" namespace="/">
        <action name="jsonsample" class="net.action.JsonSample">
             <result type="json" />
        </action>
    </package>
</struts>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<sj:head jqueryui="true" />
<div id="col3">
    <div id="col3_content" class="clearfix">
        <s:form id="formSelectReload" action="jsonsample" theme="simple"
            cssClass="yform">
            <fieldset>
                <legend>AJAX Form</legend>
                <div class="type-text">
                    <label for="language">Country: </label>
                    <s:url id="remoteurl" action="jsonsample" namespace="/"/>
                     <sj:select href="%{remoteurl}" id="country" onChangeTopics="reloadsecondlist" name="country"
                                list="countryMap" listKey="myKey" listValue="myValue" emptyOption="false"
                                headerKey="-1" headerValue="Please Select a Country"/>
                </div>
                <div class="type-text">
                    <label for="echo">State: </label>
                    <s:url id="remoteurl" action="jsonsample" namespace="/"/>
                     <sj:select href="%{remoteurl}" id="stateID" onChangeTopics="reloadThirdlist" formIds="formSelectReload"
                                reloadTopics="reloadsecondlist" name="state" 
                                list="stateMap" listKey="myKey" listValue="myValue" emptyOption="false"
                                headerKey="-1" headerValue="Please Select a State"/>
                </div>          
                <div class="type-text">
                    <label for="echo">City: </label>
                    <s:url id="remoteurl" action="jsonsample" namespace="/"/>
                     <sj:select href="%{remoteurl}" id="cityId" formIds="formSelectReload" reloadTopics="reloadThirdlist"
                                name="echo" list="cityList" emptyOption="false"
                                headerKey="-1" headerValue="Please Select a City"/>
                </div>      
            </fieldset>
        </s:form>
    </div>
</div>
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;

public class JsonSample extends ActionSupport {

    private Map<String,String> countryMap;
    private Map<String,String> stateMap;
    private List<String> cityList;

    private String country;
    private String state;
    private String city;

     public String execute() {

        countryMap = new HashMap<String,String>();
        countryMap.put("1", "USA");
        countryMap.put("2", "India");

        stateMap = new HashMap<String,String>();
        if(country != null && country.equalsIgnoreCase("1")){
            stateMap.put("1", "New York");
            stateMap.put("2", "new jersey");
        } else if(country != null && country.equalsIgnoreCase("2")){
            stateMap.put("1", "Karnataka");
            stateMap.put("2", "Andhra Pradesh");
        } 

        cityList = new ArrayList<String>();
        if(country != null && country.equalsIgnoreCase("1") && state != null && state.equalsIgnoreCase("1")){
            cityList.add("New York City 1");
            cityList.add("New York City 2");
        } else if(country != null && country.equalsIgnoreCase("1") && state != null && state.equalsIgnoreCase("2")){
            cityList.add("New Jersey City 1");
            cityList.add("New Jersey City 2");
        } else if(country != null && country.equalsIgnoreCase("2") && state != null && state.equalsIgnoreCase("1")){
            cityList.add("Karnataka City 1");
            cityList.add("Karnataka City 2");
        } else if(country != null && country.equalsIgnoreCase("2") && state != null && state.equalsIgnoreCase("2")){
            cityList.add("AP City 1");
            cityList.add("Ap City 2");
        } 

        return SUCCESS;
    }

    public String getJSON() {
        return execute();
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getCity() {
        return city;
    }

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

    public Map<String, String> getCountryMap() {
        return countryMap;
    }

    public Map<String, String> getStateMap() {
        return stateMap;
    }

    public List<String> getCityList() {
        return cityList;
    }

    public String index() {
        return "success";
    }
}
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.16.3.jar
struts2-jquery-plugin-3.7.0.jar
struts2-json-plugin-2.3.16.3.jar
xwork-core-2.3.16.3.jar