高手些来帮我看一下struts标签怎么在另一个JSP页面显示我上传的图片 先将文件名保存到request中,比如request.setAttribute("filename",filename);然后在显示图片的页面:<img src="<%=上传文件夹所在的路径+request.getAttribute("filename")%>" /> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class FileAction extends Action {/** Generated Methods*//*** Method execute** @param mapping* @param form* @param request* @param response* @return ActionForward* @throws IOException* @throws FileNotFoundException*/public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws FileNotFoundException, IOException {request.setCharacterEncoding("utf-8");DynaActionForm dform = (DynaActionForm) form;FormFile file = (FormFile) dform.get("file");if (file == null || file.getFileSize() <= 0) {return mapping.getInputForward();}String filename = file.getFileName();InputStream is = file.getInputStream();String uploadpath = servlet.getServletContext().getRealPath("/upload");System.out.println("路径1:"+uploadpath);OutputStream os = new FileOutputStream(uploadpath + "/" + filename);System.out.println("路径2:"+os);int bytes = 0;byte[] buffer = new byte[8192];while ((bytes = is.read(buffer, 0, 8192)) != -1) {os.write(buffer, 0, bytes);}os.close();is.close();file.destroy();request.setParameter("src",uploadpath + "/" + filename);return mapping.findForward("fileok");}fileok.jsp只写了body部分------------------------------------------<img src="<%=request.getParameter("src")%>" />} 还是不行哟!获取不了的!而且request.setParameter("src",uploadpath + "/" + filename);根本没有request.setParameter();报错的! 应该是request.setAttribute("src",uploadpath + "/" + filename); 在线急问struts2新手求救!简单的问题,解决马上给分 (急)怎么从web服务器(Tomcat服务器)上下载指定的文件? 配置structs2.2.3 一个JSP代码显示问题,很急!!!! strust 的错误 ibatis如何进行多表连接查询 ResultSet.getString("columnName")读取数值时出错? 求hibernate 能在tomcat下跑起来的web应用 范例 请问在一台机子上能不能同时登陆两个用户? 有人知道jive的源代码再那下载吗??? 朋友们给介绍本学习struts的书!谢谢 大家谈谈在JSP开发中一般都使用什么框架
/*
* Generated Methods
*//**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws IOException
* @throws FileNotFoundException
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws FileNotFoundException, IOException {request.setCharacterEncoding("utf-8");
DynaActionForm dform = (DynaActionForm) form;
FormFile file = (FormFile) dform.get("file");
if (file == null || file.getFileSize() <= 0) {
return mapping.getInputForward();
}String filename = file.getFileName();
InputStream is = file.getInputStream();
String uploadpath = servlet.getServletContext().getRealPath("/upload");
System.out.println("路径1:"+uploadpath);
OutputStream os = new FileOutputStream(uploadpath + "/" + filename);
System.out.println("路径2:"+os);
int bytes = 0;
byte[] buffer = new byte[8192];
while ((bytes = is.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytes);
}
os.close();
is.close();
file.destroy();
request.setParameter("src",uploadpath + "/" + filename);
return mapping.findForward("fileok");
}
fileok.jsp只写了body部分
------------------------------------------
<img src="<%=request.getParameter("src")%>" />}