日期:2014-05-17  浏览次数:20790 次

我难道那里写错了吗?
本帖最后由 Gemerl 于 2013-06-30 11:56:23 编辑
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>



html:

<h3>上传文件</h3>
    <form action="photoAction.action" method="post" enctype="application/x-www-form-urlencoded">
     <input type="file" name="photo" /><br/>
     <input type="submit" value="提交"/>
    </form>

action:

import com.jspsmart.upload.File;
import com.opensymphony.xwork2.ActionSupport;

public class PhotoAction extends ActionSupport{
private File photo;

public File getPhoto() {
return photo;
}

public void setPhoto(File photo) {
this.photo = photo;
}

@Override
public String execute() throws Exception {
System.out.println(photo);
System.out.println(photo.getFilePathName());
return SUCCESS;
}
}

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <constant name="struts.devMode" value="true" /> <!--开发模式无需重启服务器-->
    <constant name="struts.ui.theme" value="simple" />  <!--//<S:>标签简单风格-->
      
    <package name="default" namespace="/" extends="struts-default">


<action name="photoAction" class="com.action.PhotoAction">