Note that there are some explanatory texts on larger screens.

plurals
  1. POUpload Image and Save Url with Struts
    text
    copied!<p>i have some code to upload image to server with struts2.After upload i want to show my image as thumbnail image and send path of image which i have uploaded to database.I confuse how make it can works</p> <p>This is my Action Code.Cimande Action is extend from ActionSupport . </p> <pre><code>package com.maetrika.jagatoko.controller; import java.io.File; import java.io.FilePermission; import javax.servlet.http.HttpServletRequest; import org.apache.commons.io.FileUtils; import org.blueoxygen.cimande.commons.CimandeAction; public class FileUpload extends CimandeAction{ private File upload; private String uploadContentType; private String uploadFileName; private String fileCaption; private HttpServletRequest servletRequest; File file; public String execute() throws Exception{ try{ //String filePath=servletRequest.getRealPath("/"); String filePath=servletRequest.getSession().getServletContext().getRealPath("/"); File fileToCreate=new File(filePath, this.uploadFileName); FileUtils.copyFile(upload, fileToCreate); }catch (Exception e) { e.printStackTrace(); return INPUT; // TODO: handle exception } return SUCCESS; } 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() { System.out.println("=======================" + uploadFileName); return uploadFileName; } public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; } public String getFileCaption() { return fileCaption; } public void setFileCaption(String fileCaption) { this.fileCaption = fileCaption; } public HttpServletRequest getServletRequest() { return servletRequest; } public void setServletRequest(HttpServletRequest servletRequest) { this.servletRequest = servletRequest; } public File getFile() { return file; } public void setFile(File file) { this.file = file; } } </code></pre> <p>I use velocity for view. This is my code for Upload Image</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="post" action="doUpload" enctype="multipart/form-data"&gt; &lt;table border="0" cellpadding="2"&gt; &lt;tr&gt; &lt;td&gt;Upload Gambar Produk&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="file" name="upload"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" value="submit"/&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>i'm newbie on java programming.Help me please..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload