这句话,给解释下,尤其是引号,每个引号和谁匹配,什么作用

mingchaoyan mingchaoyan 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
out.println("<img height=122 width=130 src=\""+request.getContextPath()+"/PhotoServlet?photoId="+s+"\">");
这句话,给解释下,尤其是引号,每个引号和谁匹配,什么作用,我要的是仔细回答,每个引号
其中PhotoServlet的代码如下

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.album.AlbumDAOBean;
import com.javabean.AlbumPhoto;

public class PhotoServlet extends HttpServlet {
//处理POST请求
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
response.setContentType("image/jpeg");

String photoId=request.getParameter("photoId");
byte[] bi=null;
OutputStream os=null;
//获取图片
Vector vec=AlbumDAOBean.getPhoto(photoId);

for(Enumeration enu=vec.elements();enu.hasMoreElements();) {

AlbumPhoto ap=(AlbumPhoto)enu.nextElement();
bi=ap.getPhotoByte();
}
try {//输出图片
os=response.getOutputStream();
os.write(bi);
os.flush();
} catch (IOException ie) {
ie.printStackTrace();
} finally {
os.close();
}
}
//处理GET请求
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
this.doPost(request,response);
}
}


这个是先通过getPhotoByte(),然后OutputStream的对象的write将图片的字节数组写入输出流(因为图片是存储在数据库中),假如我现在把图片存在文件目录中,且可以通过getPhotoPath(photoId)取得路径,求相同功能的代码写法;
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
mingchaoyan
Web 开发 81,108 成员 341,721 内容