Announcement Announcement Module
Collapse
No announcement yet.
How to getRealPath??? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to getRealPath???

    I hava Class FileUploadAction.java

    public class FileUploadAction extends AbstractAction implements Serializable {

    @Override
    protected Event doExecute(RequestContext rc) throws Exception {
    MultipartFile file = rc.getRequestParameters().getRequiredMultipartFile ("file");
    String fileName = null;
    InputStream inputStream = null;
    OutputStream outputStream = null;
    if (file.getSize() > 0) {
    try {
    inputStream = file.getInputStream();
    //
    outputStream = new FileOutputStream("c:\\" +getRealPath+ file.getOriginalFilename());
    System.out.println("fileName:" + file.getOriginalFilename());
    int readBytes = 0;
    byte[] buffer = new byte[10000];
    while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
    outputStream.write(buffer, 0, readBytes);
    }
    outputStream.close();
    inputStream.close();
    System.out.println("fileName:" + file.getOriginalFilename());
    } catch (IOException ex) {
    Logger.getLogger(FileUploadAction.class.getName()) .log(Level.SEVERE, null, ex);
    return error();
    }
    rc.getFlashScope().put("file", new String(file.getBytes()));
    return success();
    } else {
    return error();
    }
    }
    }
    and file Flow.xml

    <var name="fileUploadAction" class="supportiveLearning.service.FileUploadAction "/>
    <on-start>
    <evaluate expression="userBean" result="flowScope.user" />

    </on-start>

    <view-state id="fileupload" model="user">
    <transition on="save" to="fileupload">
    <evaluate expression="fileUploadAction.doExecute"
    result="" result-type=""/>
    </transition>
    <transition on="cancel" to="newPage"/>
    </view-state>

    <view-state id="newPage">
    <!-- <transition on="book" to="main" />-->
    </view-state>

    <subflow-state id="main" subflow="main-flow">

    </subflow-state>

    and fileupload.xhml

    <form name="submitForm" method="post" enctype="multipart/form-data">
    <table>
    <tr>
    <td>
    File:
    </td>
    <td>
    <input type="file" name="file"></input>
    </td>
    </tr>
    <tr>
    <td colspan="2"> </td>
    </tr>
    <tr>
    <td colspan="2" class="buttonBar">
    <input type="submit" name="_eventId_cancel" value="Cancel" />

    <input type="submit" name="_eventId_upload" value="Upload Photo" />
    </td>
    </tr>
    </table>
    </form>
    I don't know how get getRealPath for image or *.doc. etc

    Everybody can help me!!!

    Thank you so much!
Working...
X