Allow multiple images upload in struts2

34 views
Skip to first unread message

Pooja Tekwani

unread,
Aug 14, 2013, 6:06:52 AM8/14/13
to java-bra...@googlegroups.com
Hello,
If I try to upload three images at a time, than it is generating an error "No result defined for action" and my code is as per follows:
QuestionAction.java

    public void imageUpload_ans(String filename, File file){
        try {
            String filePath = "F:/bigroshan/EzySystemTest/images/";
            File fileToCreate = new File(filePath, filename);
            System.out.println(filename);
            FileUtils.copyFile(file, fileToCreate);
            answerTable.setAnswerImage(filename);
        } catch(Exception e) {
            System.out.println("Error");
            answerTable.setAnswerImage("");
        }
    } and struts.xml
        <action name="addQuestionAnswerToDB" class="com.digitize.ezysystemtest.QuestionAnswerAction"
            method="addQuestionAnswerToDB">
            <interceptor-ref name="fileUpload">
            <param name="allowedTypes">
                image/png,image/gif,image/jpeg,image/pjpeg
            </param>
        </interceptor-ref>
        <interceptor-ref name="defaultStack"></interceptor-ref>
            <result name="success" type="redirect">questionAnswer</result>
        </action>

and index.jsp

<s:file id="ans1" formIds="formQuestionAnswer" name="ans1Image" label="Answer 1" />
<s:file id="ans2" formIds="formQuestionAnswer" name="ans2Image" label="Answer 2" />
<s:file id="ans3" formIds="formQuestionAnswer" name="ans3Image" label="Answer 3" />
Reply all
Reply to author
Forward
0 new messages