jsp页面中的代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.course.dao.DirectoryDAO"%>
<%@page import="com.course.po.Directory"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>添加资源</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet" rev="stylesheet" href="css/style.css" type="text/css" media="all" />
 <style type="text/css">
<!--
.atten {font-size:12px;font-weight:normal;color:#F00;}
-->
</style>
 <%! int pid; %>
 <script type="text/javascript">
 function reload(value)
 {
  location.href="<%=path%>/admin/addSource.jsp?id="+value;
 }
  </script>
  </head>
  
  <body class="ContentBody">
   <center>
   <table width="99%" border="0" cellpadding="0" cellspacing="0" class="CContent">
    <div id="source">
       <h2>添加资源</h2>
          <s:actionerror/>
   <form name="form1" method="post" action="uploadsource.action"  enctype="multipart/form-data">
     <table>
     <tr>
       <td align="right">大类类型</td>
       <td><select name="bigtype" id="big" onChange="reload(this.value)" >
       <%
       String id=request.getParameter("id");
       if(id==null)
       id="-1";
       DirectoryDAO cdao=new DirectoryDAO();
       ArrayList<Directory> arr=cdao.getDirectoryByPidForSource(0);
          for(Directory c:arr)
       {
       if(id.equals("-1"))
       id=String.valueOf(c.getDirectoryId()); //第一次进入这个页面时,获得第一个大类的ID
       %>
       <option <%=(id.equals(String.valueOf(c.getDirectoryId()))?"selected":"")%>   value="<%=c.getDirectoryId()%>"><%=c.getDirectoryName()%></option>
       <%
       }
       %>
         </select>
       </td>
      </tr>
      <tr>
       <td align="right">小类类型</td>
       <td>
       <select name="smalltype" id="small">
       <%
       String smallid=request.getParameter("smalltype");
       if(smallid==null) smallid="-1";
       DirectoryDAO cdao1=new DirectoryDAO();
       ArrayList<Directory> arr1=cdao1.getDirectoryByPidForSource(Integer.parseInt(id));
       for(Directory c:arr1)
       {
       %>
       <option  <%=(smallid.equals(String.valueOf(c.getDirectoryId()))?"selected":"")%>  value="<%=c.getDirectoryId()%>"><%=c.getDirectoryName()%></option>
       <%
       }
       %>
       </select>
        </td>
     </tr>
    <tr>
      <td align="right">资源文件</td>
      <td><input type="file"  name="myFile"></td>
      <td>只允许上传swf格式的文件,若不是请先转换</td>
    </tr>
    
    <tr>
      <td colspan="2" align="center">
        <input type="submit" name="Submit" value="提交" >
    </td>
    </tr>
    
    <tr>
      <td colspan="2" >&nbsp;</td>
    </tr>
   </table>
   </form>
 </table>
 </center>
  </body>
</html>

解决方案 »

  1.   

    。。看的很累 强烈建议不要在jsp里加java代码
      

  2.   

    基本上不用看了,这长代码看得也累,我告诉你吧,struts2获取表单的值是这样的,在action中声明你需要获取的内容,select提交的时候,会提交当前选中的值,只要定义好select的name属性,跟action中声明的变量名一致,这样表单提交的时候,后台就能获取到值了。
      

  3.   

    在你的action中设置bigtype //大类smalltype //小类这俩个全局属性  并生成setter  getter在execute 里就可以收到值了。
      

  4.   

    如果那个下拉框的name="XXX",在action里面写上setXXX()和getXXX()方法即可获取值。
      

  5.   

    各位朋友你们好:
        
       我就是按照你说的这个方法做的,但是smalltype依然获取到的是null,代码中的大类和小类意思主要就是实现目录对应的一级和二级,当一级目录改变时,二级目录也跟着改变,然后是要在二级目录下上传文件,在action中需要获取二级目录的值,也就是smalltype,不知道为什么像你那样说的,获取不到呢?
      

  6.   

    因为你的select中的option中可能没有获取到啊,你先测试一下弹出了,看有没值
      

  7.   

    enctype="multipart/form-data"> 这种类型,不知道LZ用哪个open source上传,要用open source中的Request取值