Hello, first I would like to thank you for reading my email.
I am trying out some examples for uploading a file. And I always get HTTP
500 error from tomcat.
I can't see why, I followed and copied the example. For sure I missed
something but I don't know what?
I tried debugging but I failed because IDE don't enter the execute() method.
*The error is:*
java.lang.RuntimeException: Unable to load bean
org.apache.struts2.dispatcher.multipart.MultiPartRequest (jakarta) -
[unknown location]
do need do extra configurations? please help?
*here's my JSP:*
<[EMAIL PROTECTED] language="java" contentType="text/html; charset=ISO-8859-1"%>
<[EMAIL PROTECTED] prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Ryan file upload</title>
</head>
<body>
*<s:form action="upload" method="post"
enctype="multipart/form-data">*
<s:file name="file" label="File" />
<s:submit />
*</s:form>*
</body>
</html>
*here's my Action:*
*package* manning.ryan;
*import* java.io.File;
*import* java.io.IOException;
*import* com.opensymphony.xwork2.ActionSupport;
*public class* UploadAction *extends* ActionSupport {
@Override
*public* String *execute*() {
*try* {
getUploadService().uploadFile(getFile(), getFileName(),
getFileSystemPath());
} *catc**h* (IOException e) {
e.printStackTrace();
}
*return* *SUCCESS*;
}
/* File Upload JavaBeans */
File file;
String fileContentType;
String fileSystemPath;
String fileName;
*public* File getFile() {
*return *file;
}
*public* *void* setFile(File file) {
*this*.file = file;
}
*public* String getFileContentType() {
*return *fileContentType;
}
*public* *void* setFileContentType(String fileContentType) {
*this*.fileContentType = fileContentType;
}
*public* String getFileSystemPath() {
*return *fileSystemPath;
}
*public* *void* setFileSystemPath(String fileSystemPath) {
*this*.fileSystemPath = fileSystemPath;
}
*public* String getFileName() {
*return *fileName;
}
*public* *void* setFileName(String fileName) {
*this*.fileName = fileName;
}
*public* UploadService getUploadService() {
*return *new UploadService();
}
}
*here's my UploadService.java:*
*package *manning.ryan;
*import* java.io.File;
*import* java.io.FileInputStream;
*import* java.io.FileOutputStream;
*import* java.io.IOException;
*public class* UploadService {
*public* *void* *uploadFile*(*File* file, *String* fileName,
*String*fileSystemPath)
*throws* IOException {
FileInputStream in = *null*;
FileOutputStream out = *null*;
String folderName = fileSystemPath;
File dir = *new* File(folderName);
*if* (!dir.exists()) {
dir.mkdir();
}
String targetPath = dir.getPath() + dir.*separator* + fileName;
System.*out*.println("writing file to " + targetPath);
File fileDestination = *new* File(targetPath);
*try* {
in = new FileInputStream(file);
out = new FileOutputStream(fileDestination);
*int* i;
*while*((i = in.read()) != -1) {
out.write(i);
}
} *finally* {
*if* (out != *null*) out.close();
*if* (in != *null*) in.close();
}
}
}
*here's my struts-config:*
<?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>
<package name="ryan" namespace="/ryan" extends="struts-default">
<action name="addFile">
<result>
/ryan/ryan.jsp
</result>
</action>
<action name="upload" class="manning.ryan.UploadAction">
<param name="fileSystemPath">./myFiles/</param>
<result>/ryan/uploadSuccess.jsp</result>
<result name="input">/ryan/ryan.jsp</result>
</action>
</package>
</struts>
--
warmest regards,
Ryan Webb - Philippines
email: [EMAIL PROTECTED]