我能够上传我的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