struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ryan webb" <>
Subject Struts 2: What do i need to do to be able to upload files
Date Thu, 20 Nov 2008 06:23:59 GMT
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:*
<%@page language="java" contentType="text/html; charset=ISO-8859-1"%>
<%@taglib prefix="s" uri="/struts-tags"%>

    <title>Ryan file upload</title>
        *<s:form action="upload" method="post"
            <s:file name="file" label="File" />
            <s:submit />

*here's my Action:*
*package* manning.ryan;


*import* com.opensymphony.xwork2.ActionSupport;

*public class* UploadAction *extends* ActionSupport {

    *public* String *execute*() {
        *try* {
            getUploadService().uploadFile(getFile(), getFileName(),
        } *catc**h* (IOException e) {
        *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*
*package *manning.ryan;


*public class* UploadService {

    *public* *void* *uploadFile*(*File* file, *String* fileName,
*throws* IOException {
        FileInputStream in = *null*;
        FileOutputStream out = *null*;

        String folderName = fileSystemPath;
        File dir = *new* File(folderName);

        *if* (!dir.exists()) {

        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 = != -1) {
        } *finally* {
            *if* (out != *null*) out.close();
            *if* (in != *null*) in.close();


*here's my struts-config:*
<?xml version="1.0" encoding="UTF-8"?>
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

    <package name="ryan" namespace="/ryan" extends="struts-default">
        <action name="addFile">

        <action name="upload" class="manning.ryan.UploadAction">
            <param name="fileSystemPath">./myFiles/</param>
            <result name="input">/ryan/ryan.jsp</result>

warmest regards,
Ryan Webb - Philippines


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message