小弟做项目使用liferay+struts2+spring+hibernate:今天写到文件上传我使用的是struts2中的文件上传可在action页面却接受不到值,现在把代码贴出来请大家帮忙看看,拜托了!!!
1.jsp页面:
<!--对联广告表单--><form style="display:none" id="menu_item1" name="form" action="<s:url action="AddCoupletAdverAction" />" method="post" enctype="multipart/form-data" >
<table width="60%" border="1" bordercolor="blue" align="center">
  <tr>
    <td colspan="2" align="center" bgcolor="#CCCCFF" class="duilian_ad">对联广告添加</td>
  </tr>
  <tr>
    <td width="50%">显示:
        <input name="isShow" type="radio"  value="Y"  /> 是
        <input name="isShow" type="radio"  value="N"  /> 否
   </td>
    <td>广告标题:
   
        <input type="text" name="adTitle"  />
   </td>
  </tr>
  <tr>
    <td>左边图片:
      
        <input type="file" name="file"  />
   </td>
    <td>对应Url:
    
        <input type="text" name="adUrl1"  />
    </td>
  </tr>
  <tr>
    <td>右边图片:
      
        <input type="file" name="file"  />
    </td>
    <td>对应Url:
    
        <input type="text" name="adUrl2"  />
   </td>
  </tr>
  <tr>
    <td align="right">
      <input type="submit" value="添加"  onclick="Display(1)"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   </td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="reset" value="重置"  />
    </td>
  </tr>
  
</table>
</form>
 2.action页面代码:
public class AddCoupletAdverAction extends DefaultActionSupport {
private static final long serialVersionUID = 1L;
// request the value of the form
private String adTitle;
private String adUrl1;
private String adUrl2;
private String isShow;
private List<File> file;
private List<String> fileFileName;
private List<String> fileContentType;
public String getAdTitle() {
return adTitle;
} public void setAdTitle(String adTitle) {
this.adTitle = adTitle;
} public String getAdUrl1() {
return adUrl1;
} public void setAdUrl1(String adUrl1) {
this.adUrl1 = adUrl1;
} public String getAdUrl2() {
return adUrl2;
} public void setAdUrl2(String adUrl2) {
this.adUrl2 = adUrl2;
} public String getIsShow() {
return isShow;
} public void setIsShow(String isShow) {
this.isShow = isShow;
} public List<File> getFile() {
return file;
} public void setFile(List<File> file) {
this.file = file;
} public List<String> getFileFileName() {
return fileFileName;
} public void setFileFileName(List<String> fileFileName) {
this.fileFileName = fileFileName;
} public List<String> getFileContentType() {
return fileContentType;
} public void setFileContentType(List<String> fileContentType) {
this.fileContentType = fileContentType;
} /*
 * 重写父类的execute方法
 */

@Override
public String execute() throws Exception {
// TODO Auto-generated method stub // 验证表单数据是否传到action页面

System.out.println("广告标题是:" + this.adTitle);
System.out.println("广告url1:" + this.adUrl1);
System.out.println("广告url2:" + this.adUrl2);
System.out.println("广告是否显示:" + this.isShow);
System.out.println("广告图片名称:" + this.fileFileName);

for (int i = 0; i < file.size(); ++i) {
InputStream is = new FileInputStream(file.get(i));
String root = ServletActionContext.getRequest().getRealPath("/upload");
File destFile = new File(root, this.getFileFileName().get(i));
FileOutputStream os = new FileOutputStream(destFile);
byte[] buffer = new byte[400];
int length = 0;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
is.close();
os.close(); }
return SUCCESS; }}
3.错误:
// 验证表单数据是否传到action页面

System.out.println("广告标题是:" + this.adTitle);
System.out.println("广告url1:" + this.adUrl1);
System.out.println("广告url2:" + this.adUrl2);
System.out.println("广告是否显示:" + this.isShow);
System.out.println("广告图片名称:" + this.fileFileName);
这些打印出来的结果全都是:null
这个问题困扰小弟整整两天了,请大家看看该怎么解决,小弟感激不尽。