Upload.jsp:
代码
-
<
html:form
action
=
"UploadAction.do"
method
=
"POST"
enctype
=
"multipart/form-data"
>
-
<
table
width
=
"100%"
height
=
"100%"
border
=
"0"
cellpadding
=
"0"
cellspacing
=
"0"
>
-
<
tr
bgcolor
=
"#C8E8F0"
id
=
"advertServer"
>
-
<
td
align
=
"right"
>
选择文件
</
td
>
-
<
td
height
=
30
bgcolor
=
"#F7FBFF"
>
-
<
html:file
property
=
"theFile"
styleId
=
"theFile"
styleClass
=
"textbox"
size
=
"50"
>
-
</
td
>
-
</
tr
>
-
</
table
>
-
</
html:form
>
UpLoadForm.java:
代码
-
- public class UpLoadForm extends ValidatorForm {
-
- private FormFile theFile;
-
- public FormFile getTheFile() {
return theFile;
} - public void setTheFile(FormFile theFile) {
this.theFile= theFile;
} - }
UpLoadAcion.java
代码
- public class UpLoadAction extends BaseAction {
-
- public ActionForward execute(ActionMapping mapping, ActionForm argForm,HttpServletRequest request, HttpServletResponse response) {
- UpLoadForm form = (UpLoadForm)argForm;
- FormFile uploadFile = (FormFile) form.getTheFile();
- ServletContext context = getServlet().getServletContext();
- String filePath = context.getRealPath("/");
- stream = formFile.getInputStream();
- bos = new FileOutputStream(fileName);
- int bytesRead = 0;
- byte[] buffer = new byte[8192];
- while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {bos.write(buffer, 0, bytesRead);
- mapping.findForward("success");
- }
- }
posted on 2007-02-02 14:02
阿mjay 阅读(950)
评论(0) 编辑 收藏