<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 14, comments - 22, trackbacks - 0, articles - 4
      BlogJava :: 首頁 ::  :: 聯系 :: 聚合  :: 管理

    接著上次的話題,下面的就是學生注冊時需要的學院,專業,班級,三層列表,
    學院:
    <html:select property="instituteId" onchange="getDepartments(this.value)">
    ?????<html:options collection="institutes" property="value" labelProperty="label"/>
    ????</html:select>

    專業:
    <html:select property="departmentId" styleId="department" onchange="getClasses(this.value)"></html:select>
    班級:
    <html:select property="classId" styleId="classid" ></html:select>

    學院是上來就應該有的,我們把他放到了LabelValueBean里
    public Vector<LabelValueBean> getInstitutes()
    ??? {
    ??????? Connection connection = null;
    ??????? PreparedStatement pstmt = null;
    ??????? ResultSet rs = null;
    ??????? try
    ??????? {
    ??????????? connection = getConnection();
    ??????????? pstmt = connection.prepareStatement( "select * from institute" );
    ??????????? rs = pstmt.executeQuery();
    ??????????? Vector<LabelValueBean> institutes = new Vector<LabelValueBean>();
    ??????????? institutes.add( new LabelValueBean( "請選擇所在學院", "" ) );
    ??????????? while ( rs.next() )
    ??????????? {
    ??????????????? institutes.add( new LabelValueBean(
    ??????????????????????? rs.getString( "institute" ), rs.getString( "id" ) ) );
    ??????????? }
    ??????????? return institutes;
    ??????? }
    ??????? catch ( Exception e )
    ??????? {
    ??????????? e.printStackTrace();
    ??????? }
    ??????? finally
    ??????? {
    ??????????? close( rs );
    ??????????? close( pstmt );
    ??????????? close( connection );
    ??????? }
    ??????? return null;
    ??? }
    而當它選擇了一個學院后,相應的getDepartments(this.value)的js腳本就該工作了,還是四步
    var xmlHttp;
    function createXMLHttpRequest()
    {
    ?if (window.XMLHttpRequest)
    ?{
    ??xmlHttp = new XMLHttpRequest();
    ?}
    ?else if (window.ActiveXObject)
    ?{
    ??xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    ??? }
    }
    發出請求
    function getDepartments(institute)
    {
    ?createXMLHttpRequest()
    ?var url = "ajax.do?institute="+institute+"&method=getDepartments"
    ?xmlHttp.open("GET",url, true)
    ?xmlHttp.onreadystatechange = departments
    ?xmlHttp.send(null)
    }
    處理響應
    function departments()
    {
    ?if (xmlHttp.readyState == 4)
    ?{
    ??if (xmlHttp.status == 200)
    ??{
    ???resText = xmlHttp.responseText
    ???each = resText.split("|")
    ???buildSelect( each, document.getElementById("departmentId"), "請選擇所在專業");
    ??}
    ?}
    }
    function buildSelect(str,sel,label)
    {
    ?sel.options.length=0;
    ?sel.options[sel.options.length]=new Option(label,"")
    ?for(var i=0;i<str.length;i++)
    ?{
    ??each=str[i].split(",")
    ??sel.options[sel.options.length]=new Option(each[0],each[1])
    ?}
    }
    我把從數據庫中得到的各個專業進行了編碼,之后再這里再回歸回去,下面的是編碼過程
    public StringBuffer getDepartmentsByInstituteIdForAjax( Long instituteId )
    ??? {
    ??????? Connection connection = null;
    ??????? PreparedStatement pstmt = null;
    ??????? ResultSet rs = null;
    ??????? try
    ??????? {
    ??????????? connection = getConnection();
    ??????????? pstmt = connection
    ??????????????????? .prepareStatement( "select * from department where instituteID=?" );
    ??????????? pstmt.setLong( 1, instituteId );
    ??????????? rs = pstmt.executeQuery();
    ??????????? StringBuffer sb = new StringBuffer();
    ??????????? while ( rs.next() )
    ??????????? {
    ??????????????? sb.append( rs.getString( "department" ) + ","
    ??????????????????????? + rs.getLong( "id" ) );
    ??????????????? if ( !rs.isLast() ) sb.append( "|" );
    ??????????? }
    ??????????? return sb;
    ??????? }
    ??????? catch ( Exception e )
    ??????? {
    ??????????? e.printStackTrace();
    ??????? }
    ??????? finally
    ??????? {
    ??????????? close( rs );
    ??????????? close( pstmt );
    ??????????? close( connection );
    ??????? }
    ??????? return null;
    ??? }
    當然這些都是由
    public ActionForward getDepartments( ActionMapping mapping,
    ??????????? ActionForm form, HttpServletRequest req, HttpServletResponse res )
    ??????????? throws Exception
    ??? {
    ??????? Service service = getService();
    ??????? res.getWriter().write(
    ??????????????? service.getDepartmentsByInstituteIdForAjax(
    ??????????????????????? Long.parseLong( req.getParameter( "institute" ) ) )
    ??????????????????????? .toString() );
    ??????? return null;
    ??? }
    來控制

    ===========班級的再這里
    public ActionForward getClasses( ActionMapping mapping, ActionForm form,
    ??????????? HttpServletRequest req, HttpServletResponse res ) throws Exception
    ??? {
    ??????? Service service = getService();
    ??????? res.getWriter().write(
    ??????????????? service.getClassesByDepartmentIdForAjax(
    ??????????????????????? Long.parseLong( req.getParameter( "department" ) ) )
    ??????????????????????? .toString() );
    ??????? return null;
    ??? }


    public StringBuffer getClassesByDepartmentIdForAjax( Long departmentId )
    ??? {
    ??????? Connection connection = null;
    ??????? PreparedStatement pstmt = null;
    ??????? ResultSet rs = null;
    ??????? try
    ??????? {
    ??????????? connection = getConnection();
    ??????????? pstmt = connection
    ??????????????????? .prepareStatement( "select * from class where departmentID=?" );
    ??????????? pstmt.setLong( 1, departmentId );
    ??????????? rs = pstmt.executeQuery();
    ??????????? StringBuffer sb = new StringBuffer();
    ??????????? while ( rs.next() )
    ??????????? {
    ??????????????? sb.append( rs.getString( "class" ) + "," + rs.getLong( "id" ) );
    ??????????????? if ( !rs.isLast() ) sb.append( "|" );
    ??????????? }
    ??????????? return sb;
    ??????? }
    ??????? catch ( Exception e )
    ??????? {
    ??????????? e.printStackTrace();
    ??????? }
    ??????? finally
    ??????? {
    ??????????? close( rs );
    ??????????? close( pstmt );
    ??????????? close( connection );
    ??????? }
    ??????? return null;
    ??? }

    function getClasses(department)
    {
    ?createXMLHttpRequest()
    ?var url = "ajax.do?department="+department+"&method=getClasses"
    ?xmlHttp.open("GET",url, true)
    ?xmlHttp.onreadystatechange = classes
    ?xmlHttp.send(null)
    }

    function classes()
    {
    ?if (xmlHttp.readyState == 4)
    ?{
    ??if (xmlHttp.status == 200)
    ??{
    ???resText = xmlHttp.responseText
    ???each = resText.split("|")
    ???buildSelect( each, document.getElementById("classid"), "請選擇所在班級");
    ??}
    ?}
    }


    評論

    # re: 體驗Struts(4)---用ajax實現三級下拉列表   回復  更多評論   

    2006-06-07 15:35 by 千山鳥飛絕
    不錯,好文章

    # re: 體驗Struts(4)---用ajax實現三級下拉列表   回復  更多評論   

    2007-06-22 14:30 by zhanglei
    功能可以實現但是提交出現異常:
    javax.servlet.jsp.JspException: Cannot find bean GetAddInfo in any scope

    at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:938)

    at org.apache.struts.taglib.html.OptionsCollectionTag.doStartTag(OptionsCollectionTag.java:219)

    at jsp_servlet.__rorder_add._jspService(__rorder_add.java:377)


    at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)

    問題就出在:<html:options collection="issue_type" property="value" labelProperty="label"/>標簽 提交不過去。formbean已經執行完了,但是action.do的excute方法沒有執行到。。不知道如何解決

    # re: 體驗Struts(4)---用ajax實現三級下拉列表   回復  更多評論   

    2008-08-08 09:17 by sunhe
    有沒有工程發下

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    有事在這里給我留言噢!
    主站蜘蛛池模板: 久久午夜伦鲁片免费无码| 色费女人18女人毛片免费视频| 91成人免费观看在线观看| 亚洲v国产v天堂a无码久久| 亚洲A∨精品一区二区三区下载| 无码免费午夜福利片在线| 亚洲人成电影网站| 亚洲精品动漫免费二区| 亚洲精品伦理熟女国产一区二区 | 中文字幕一区二区免费| 国产亚洲老熟女视频| 伊人久久大香线蕉免费视频| 亚洲av无码国产精品色午夜字幕| 国内精品免费视频精选在线观看| 亚洲AV无码精品色午夜在线观看 | 成全影视免费观看大全二| 亚洲日韩精品无码专区加勒比☆| 全免费一级毛片在线播放| 青青青亚洲精品国产| 亚洲欧洲自拍拍偷精品 美利坚| selaoban在线视频免费精品| 久久亚洲国产欧洲精品一| 人与禽交免费网站视频| 亚洲一本到无码av中文字幕| 亚洲高清无码专区视频| 久久国产精品国产自线拍免费| 亚洲国色天香视频| 日本免费人成黄页网观看视频| 高潮毛片无遮挡高清免费视频| 亚洲精品你懂的在线观看| 青娱分类视频精品免费2| 激情吃奶吻胸免费视频xxxx| 亚洲乱码精品久久久久..| 69成人免费视频| 免费看黄网站在线看| 亚洲综合视频在线| 免费jlzzjlzz在线播放视频| 免费一级毛片无毒不卡| 亚洲AV无码专区在线电影成人 | 精品国产亚洲一区二区在线观看 | 无码视频免费一区二三区 |