我能夠上傳我的web應用程序與struts2框架中的圖片,但我無法理解路徑。 如何獲取圖像的路徑作爲URL,以便我可以使用它在<img src="url"/>
中進一步處理。上傳後無法獲取正確的文件路徑
這是我的動作類源代碼,我提到了評論中返回的URL,但是URL對我沒有任何意義。我如何解密到實際的網址?
public class AddItemAction extends ActionSupport implements
ServletContextAware {
@Override
public void setServletContext(ServletContext arg0) {
// TODO Auto-generated method stub
}
File pic;
String picContentType;
String picFileName;
public File getPic() {
return pic;
}
public void setPic(File pic) {
this.pic = pic;
}
public String getPicContentType() {
return picContentType;
}
void setPicContentType(String picContentType) {
System.out.println("Setting conteent tuype" + picContentType);
this.picContentType = picContentType;
}
public void setPicFileName(String picFileName) {
this.picFileName = picFileName;
}
public String getPicFileName() {
return picFileName;
}
public String execute() {
File file = getPic();
String strFinalFullPathFileName = file.getAbsolutePath() + File.separator + picFileName;
System.out.println(strFinalFullPathFileName);
// This is the path returned
/*
* /Users/..../Catalina/localhost/.../upload_584d2719_13d5fdf593d__8000_00000000.tmp/IMG_20120526_083438.jpg
*
*
*/
return SUCCESS;
}
}
創建其獲取圖像的操作和使用,作爲URL的路徑。 – Quaternion 2013-03-12 18:46:06
@Quaternion你的意思是getPic();但是當我嘗試執行getPic()。getPath()時,它給了我os文件路徑,即/ Users/... – 2013-03-12 18:48:08
不要在註釋中提及實際的URL,請更新問題。 – 2013-03-12 18:52:51