我写了一个struts2上传文件的例子,出现了一个很奇怪的问题,提交表单以后,页面直接跳转到result="input"的页面,根本不会执行result="succes",请指导呀?
jsp代码如下:
<s:form action="folder_up" method="post" enctype="multipart/form-data">
<s:textfield name="file.fileName" label="文件名" cssStyle="height: auto"></s:textfield>
<s:textfield name="file.url" label="文件所在路径" cssStyle="height: auto"></s:textfield>
<s:textfield name="file.type" label="文件内容类型" cssStyle="height: auto"></s:textfield>
<s:textfield name="author" label="文件作者" cssStyle="height: auto"></s:textfield>
<s:textfield name="file.re" label="文件出处" cssStyle="height: auto"></s:textfield>
<s:textfield name="title" label="文件主题" cssStyle="height: auto"></s:textfield>
<s:textarea name="details.summary" label="内容"></s:textarea>
<s:radio list="#{'true':'是','false':'否'}" name="details.accJudge" label="是否有附件" value="是"></s:radio>
<s:file name="accUrl" label="附件位置"></s:file>
<s:submit value="上传"></s:submit>
</s:form>
action类代码如下:
private java.io.File accUrl;
private String accUrlContentType;
private String accUrlFileName;
private String savePath;
public String up() throws IOException{
author = request.getParameter("author");
title = request.getParameter("title");
/* String accUrl = request.getParameter("accUrl");
System.out.println(accUrl);*/
file.setAuthor(author);
file.setTitle(title);
details.setAuthor(author);
details.setTitle(title);
String fileName = getSavePath()+"\\"+getAccUrlFileName();
FileInputStream fis = new FileInputStream(getAccUrl());
FileOutputStream fos = new FileOutputStream(fileName);
byte[] buffer = new byte[1024];
int len = 0;
while((len = fis.read(buffer)) > 0){
fos.write(buffer, 0, len);
}
中间省略了set和get方法。
struts.xml文件如下
<action name="folder_*" class="folderAction" method="{1}">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">application/pdf,application/msword,text/html</param>
<param name="maximumSize">90000000</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<param name="savePath">/save</param>
<result name="input">/SharePoint/main.jsp</result>
<result name="success">/success.jsp</result>
</action>
jsp代码如下:
<s:form action="folder_up" method="post" enctype="multipart/form-data">
<s:textfield name="file.fileName" label="文件名" cssStyle="height: auto"></s:textfield>
<s:textfield name="file.url" label="文件所在路径" cssStyle="height: auto"></s:textfield>
<s:textfield name="file.type" label="文件内容类型" cssStyle="height: auto"></s:textfield>
<s:textfield name="author" label="文件作者" cssStyle="height: auto"></s:textfield>
<s:textfield name="file.re" label="文件出处" cssStyle="height: auto"></s:textfield>
<s:textfield name="title" label="文件主题" cssStyle="height: auto"></s:textfield>
<s:textarea name="details.summary" label="内容"></s:textarea>
<s:radio list="#{'true':'是','false':'否'}" name="details.accJudge" label="是否有附件" value="是"></s:radio>
<s:file name="accUrl" label="附件位置"></s:file>
<s:submit value="上传"></s:submit>
</s:form>
action类代码如下:
private java.io.File accUrl;
private String accUrlContentType;
private String accUrlFileName;
private String savePath;
public String up() throws IOException{
author = request.getParameter("author");
title = request.getParameter("title");
/* String accUrl = request.getParameter("accUrl");
System.out.println(accUrl);*/
file.setAuthor(author);
file.setTitle(title);
details.setAuthor(author);
details.setTitle(title);
String fileName = getSavePath()+"\\"+getAccUrlFileName();
FileInputStream fis = new FileInputStream(getAccUrl());
FileOutputStream fos = new FileOutputStream(fileName);
byte[] buffer = new byte[1024];
int len = 0;
while((len = fis.read(buffer)) > 0){
fos.write(buffer, 0, len);
}
中间省略了set和get方法。
struts.xml文件如下
<action name="folder_*" class="folderAction" method="{1}">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">application/pdf,application/msword,text/html</param>
<param name="maximumSize">90000000</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<param name="savePath">/save</param>
<result name="input">/SharePoint/main.jsp</result>
<result name="success">/success.jsp</result>
</action>
解决方案 »
- java file上传图片成功后无法查看问题
- 关于map数据传输,以及解析。
- Log4j 同一Application两份Log的问题
- 研究生复试上机可以用java吗?
- JAVA函数的调用难不,怎么应用呢?
- ibatis中nullValue设置不起作用
- 朋友们, 帮帮忙吧
- 急死了,实体bean的测试异常
- eclips3.2 + myeclipse5.0 还用单独安装tomcat吗
- 启动tomcat时窗口一闪而过,怎末解决
- 求一个java含有组织机构的权限管理的模块源码?
- 启动Tomcat时报Cannot create PoolableConnectionFactory错误。svn下载下来的同样的项目,别人没事就我的有事
</bean>