首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

跪求 SSH框架 action接不到JSP页面的值解决方案

2012-09-25 
跪求 SSH框架 action接不到JSP页面的值以下是 action的 代码package com.tc.test.actionimport java.io.F

跪求 SSH框架 action接不到JSP页面的值
以下是 action的 代码

package com.tc.test.action;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.bj.framework.action.BaseAction;
import com.tc.test.bo.UploadFile;
import com.tc.test.service.IUploadService;

public class TestUploadAction extends BaseAction{
//service 模型
private IUploadService uploadServiceImpl;
//上传文件存放路径
private String path="f:/file";
//uploadFile实体类
private UploadFile uploadFile;
//上传文件集合
private List<File> upload=new ArrayList<File>();
//上传文件名集合
private List<String> uploadFileName;
//上传文件类型集合
private List<String> uploadContentType;

public String add() {
try {

uploadServiceImpl.saveUploadFile(uploadFile,getPath(),upload,uploadContentType,uploadFileName);
} catch (Exception e) {
e.printStackTrace();
}
return "requery";
}

public String query(){
list=this.uploadServiceImpl.findAll();
return "query";
}

public String addPage(){
return "addPage";
}

public IUploadService getUploadServiceImpl() {
return uploadServiceImpl;
}
public void setUploadServiceImpl(IUploadService uploadServiceImpl) {
this.uploadServiceImpl = uploadServiceImpl;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public UploadFile getUploadFile() {
return uploadFile;
}

public void setUploadFile(UploadFile uploadFile) {
this.uploadFile = uploadFile;
}

public List<File> getUpload() {
return upload;
}

public void setUpload(List<File> upload) {
this.upload = upload;
}

public List<String> getUploadFileName() {
return uploadFileName;
}

public void setUploadFileName(List<String> uploadFileName) {
this.uploadFileName = uploadFileName;
}

public List<String> getUploadContentType() {
return uploadContentType;
}

public void setUploadContentType(List<String> uploadContentType) {
this.uploadContentType = uploadContentType;
}

}


以下是JSP页面的代码

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
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 href="images/public3.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function back(){
window.history.go(-1);
}


function addMore(){
var input_file = document.createElement("input") ;
input_file.setAttribute("type","file") ;
input_file.setAttribute("name","upload"); 

var td=document.getElementById("uploadFile");
td.appendChild(input_file);
}

function doSave(){
document.addForm.action="<%=path%>/uploadTestAction!add.action";
document.addForm.submit();
}
</script>
  <body>
  
<div class="div_title_main">上传文件</div>
  <s:form action="uploadTestAction!add.action" name="addForm" method="post" enctype="multipart/form-data">
<table class="table_list" style="word-break:break-all">
<tr>
<th width="10%">上传人</th>
<td>
<s:textfield name="uploadFile.uploadPerson"></s:textfield>
</td>
</tr>
<tr>
<th width="10%">文件</th>
<td id="uploadFile">
<s:file name="upload"></s:file> 
</td>
</tr>
 
</table>
<span class="button_01"><input type="submit" value=" 保 存 " /></span>
<span class="button_01"><input type="button" value="上传更多" onclick="addMore()"></span>
  <span class="button_01"><input type="reset" value=" 返 回" style="cursor:hand;" onclick="back();"/></span>
</s:form>
<br/><br/>
  </body>
</html>

以下是实体的内容 所有属性都已经set get application和struts也已经配置 

package com.tc.test.bo;

import java.util.Date;

/**
 * Dic entity. @author MyEclipse Persistence Tools
 */

@SuppressWarnings("serial")
public class UploadFile implements java.io.Serializable {

// Fields
private String uploadId;
private String uploadPerson;
private String uploadFileName;
private String uploadPath;
private String uploadContentType;
private Date uploadTime;

//constructor
public UploadFile() {
}

//methods
public String getUploadId() {
return uploadId;
}
public void setUploadId(String uploadId) {
this.uploadId = uploadId;
}
public String getUploadPerson() {
return uploadPerson;
}
public void setUploadPerson(String uploadPerson) {
this.uploadPerson = uploadPerson;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public Date getUploadTime() {
return uploadTime;
}
public void setUploadTime(Date uploadTime) {
this.uploadTime = uploadTime;
}

public String getUploadPath() {
return uploadPath;
}

public void setUploadPath(String uploadPath) {
this.uploadPath = uploadPath;
}
}

[解决办法]
<s:form action="uploadTestAction!add.action" name="addForm" method="post" enctype="multipart/form-data">的name属性不对啊,没有和action里面的对应起来啊,还有uploadFile里面的set和get函数写了没

热点排行