JSP显示图片/XML

1 显示图片
<%@page import="java.awt.Image"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="javax.imageio.*"%>
<%@page import="java.awt.image.BufferedImage,java.io.*;"%>

<%
	File myGifFile = new File("f:\\111.jpg");
	BufferedImage bufi = ImageIO.read(myGifFile);
	response.reset();//清除buffer
	response.setContentType("image/gif");
	ImageIO.write(bufi, "jpg", response.getOutputStream());
	out.clear();
	out = pageContext.pushBody();
%>


引用

由于jsp container在处理完成请求后会调用releasePageContet方法释放所用的PageContext object,并且同时调用getWriter方法,由于getWriter方法与在jsp页面中使用流相关的getOutputStream方法冲突,所以会造成这种异常,解决办法是:只需要在jsp页面的最后加上两条语句:  out.clear();
out=pageContext.pushBody();即可(其中out,pageContext均为jsp内置对象!)


2 显示XML
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/xml; charset=UTF-8"
	pageEncoding="UTF-8"%>

<painting>
  <aa>fadfsadf</aa>
</painting>

你可能感兴趣的:(java,html,jsp,xml,F#)