hi,
======= my jsp ==========
<%@page contentType="text/html"%>
<%@page pageEncoding="tis-620"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html:form enctype="multipart/form-data" method="POST" action="/createFuncPage.do">
<div id="upload">
<table width="100%" border="0" cellspacing="5" cellpadding="2">
<tr>
<td colspan="2" bgcolor="#B7B7FF"><strong>ระบุไฟล์ Excel ที่ต้องการใช้</strong></td>
</tr>
<tr>
<td width="18%" bgcolor="#DDDDFF"><div align="right">เลือกไฟล์ :</div></td>
<td width="82%
"><html:file property="file" /><html:errors property="file"/></td>
</tr>
</table>
<br />
</div>
<br/>
<div id="selectBase">
<table width="100%" border="0" cellspacing="5" cellpadding="2">
<tr>
<td colspan="2" bgcolor="#B7B7FF"><strong>เลือกฐานข้อมูลที่ 1 และฟังก์ชั่นที่ต้องการ </strong></td>
</tr>
<tr>
<td width="18%" bgcolor="#DDDDFF"><div align="right">ฐานข้อมูลที่ 1 : </div></td>
<td width="82%"><label>
<html:radio property="base1" value="1"/>
CUS
<html:radio property="base1" value="2"/>
WLG
<html:radio property="base1" value="3"/>
MAIN
<html:radio property="base1" value="4"/>
STOCK</label> <html:errors property="base1"/></td>
</tr>
<tr>
<td bgcolor="#DDDDFF"><div align="right">ฟังก์ชั่น :</div></td>
<td><label>
<html:radio property="function1" value="1"/>
RC
<html:radio property="function1" value="2"/>
IV
<html:radio property="function1" value="3"/>
RO
<html:radio property="function1" value="4"/>
RI</label></td>
</tr>
</table>
</div>
....
</html:form>
======== my action form ===========
/*
* MainMenuActionForm.java
*
* Created on 8 กรกฎาคม 2550, 15:17 น.
*/
package cus.web;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;
/**
*
* @author Administrator
* @version
*/
//public class MainMenuActionForm extends org.apache.struts.action.ActionForm {
public class MainMenuActionForm extends UploadActionForm {
private FormFile file;
private
String base1;
private String function1;
private String base2;
private String function2;
private String base3;
private String function3;
private String base4;
private String function4;
private String submit;
private String reset;
/**
*
*/
public MainMenuActionForm() {
super();
// TODO Auto-generated constructor stub
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
super.validate(mapping, request);
ActionErrors errors = new ActionErrors();
if (getFile() == null || getFile().getFileName().length() < 1) {
errors.add("file", new ActionMessage("error.file.required"));
// TODO: add 'error.name.required' key to your resources
}
if (getBase1() == null || getBase1().length() < 1) {
errors.add("base1", new ActionMessage("error.base1.required"));
// TODO: add 'error.name.required' key to your resources
}
return errors;
}
public String getBase1() {
return base1;
}
public void setBase1(String base1) {
this.base1 = base1;
}
public String getFunction1() {
return function1;
}
public void setFunction1(String function1) {
this.function1 = function1;
}
public String getBase2() {
return base2;
}
public void setBase2(String base2) {
this.base2 = base2;
}
public String getFunction2() {
return function2;
}
public void setFunction2(String function2) {
this.function2 = function2;
}
public String getBase3() {
return base3;
}
public void setBase3(String base3) {
this.base3 = base3;
}
public String getFunction3() {
return function3;
}
public void setFunction3(String function3) {
this.function3 = function3;
}
public String getBase4() {
return base4;
}
public void setBase4(String base4) {
this.base4 = base4;
}
public String getFunction4() {
return function4;
}
public void setFunction4(String function4) {
this.function4 = function4;
}
public String getSubmit() {
return submit;
}
public void setSubmit(String submit) {
this.submit = submit;
}
public String getReset() {
return reset;
}
public void setReset(String reset) {
this.reset = reset;
}
public FormFile getFile() {
return file;
}
public void setFile(FormFile file) {
this.file = file;
}
}
========= my action =========
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("MainMenuAction was called.");
MainMenuActionForm aForm = (MainMenuActionForm)form;
FormFile file = aForm.getFile();
System.out.println("aaa"+aForm.getBase1());
System.out.println("FILENAME = " + file.getFileName()); ====> I GOT NULL HERE
// write excel file to server directory.
FileOutputStream f = new FileOutputStream("c:/cus/" + file.getFileName());
f.write(file.getFileData());
f.close();
String path = checkFunctionToDo(aForm);
return mapping.findForward(path);
}
The file that i used for
testing is very small in size.
Hey, thank you very much for you help.
anurak