Problème d'exécution de FileUpload avec Struts 2
bonjour
j'ai realiser un TP de file upload avec struts2
mais il maffiche l'erreur suivante :
Code:
1 2 3 4 5 6
|
type Rapport d'état
message There is no Action mapped for namespace / and action name doUpload.
description La ressource demandée (There is no Action mapped for namespace / and action name doUpload.) n'est pas disponible. |
voila le tp en detail
fichiers jars utilisé :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
freemarker-2.3.16.jar
javassist-3.7.ga.jar
ognl-3.0.jar
struts2-core-2.2.1.jar
xwork-core-2.2.1.jar |
struts.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="false"/>
<package name="sample" extends="struts-default">
<action name="showUpload">
<result>/pages/upload.jsp</result>
</action>
<action name="doUpload" class="net.roseindia.StrutsFileUpload">
<result name="input">/pages/upload.jsp</result>
<result name="success">/pages/upload-success.jsp</result>
</action>
</package>
</struts> |
web.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>upload_fichier</display-name>
<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>/pages/upload.jsp</welcome-file>
</welcome-file-list>
</web-app> |
StrutsFileUpload.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
package net.roseindia;
import java.util.Date;
import java.io.File;
import com.opensymphony.xwork2.ActionSupport;
public class StrutsFileUpload extends ActionSupport {
private File upload;//The actual file
private String uploadContentType; //The content type of the file
private String uploadFileName; //The uploaded file name
private String fileCaption;//The caption of the file entered by user
public String execute() throws Exception {
return SUCCESS;
}
//getters and setters
public String getFileCaption() {
return fileCaption;
}
public void setFileCaption(String fileCaption) {
this.fileCaption = fileCaption;
}
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
} |
upload.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>File Upload Example</title>
<link href="<s:url value="/css/main.css"/>" rel="stylesheet" type="text/css"/>
</head>
<body>
<s:actionerror />
<s:fielderror />
<s:form action="doUpload" method="POST" enctype="multipart/form-data">
<tr>
<td colspan="2"><h1>File Upload Example</h1></td>
</tr>
<s:file name="upload" label="File"/>
<s:textfield name="caption" label="Caption"/>
<s:submit />
</s:form>
</body>
</html> |
success_upload.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
<%@ page
language="java"
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Showcase</title>
<link href="<s:url value="/css/main.css"/>" rel="stylesheet" type="text/css"/>
</head>
<body>
<table class="wwFormTable">
<tr>
<td colspan="2"><h1>File Upload Example</h1></td>
</tr>
<tr>
<td class="tdLabel"><label for="doUpload_upload" class="label">Content Type:</label></td>
<td><s:property value="uploadContentType" /></td>
</tr>
<tr>
<td class="tdLabel"><label for="doUpload_upload" class="label">File Name:</label></td>
<td ><s:property value="uploadFileName" /></td>
</tr>
<tr>
<td class="tdLabel"><label for="doUpload_upload" class="label">File:</label></td>
<td><s:property value="upload" /></td>
</tr>
<tr>
<td class="tdLabel"><label for="doUpload_upload" class="label">File Caption:</label></td>
<td><s:property value="caption" /></td>
</tr>
</table>
</body>
</html> |
dans le formulaire upload.jsp il s'affiche deux champs avec deux bouton
le premier parcourir fichier
et le deusième : caption il reste vide
comment reglé le probleme de cette erreur ?