相关文章
更多最近更新
更多ServletOutputStream cannot be resolved to a type
2019-03-25 13:36|来源: 网路
在使用jsp生成web图片时遇到这个问题,这是源代码中的一条语句,源代码可以执行,可是一将源码放入eclipse就会出现这个错误
源码如下:
问题补充:
以上代码在保存为jsp文件 可以在tomcat环境中 正确显示
可是一旦放入eclipse环境中就会提示那个错误
源码如下:
<!-- Fig. 6.04_01: basic.jsp 功能: JSP 绘制文本和线段 --> <%@ page language="java" contentType="image/jpeg;charset=GB2312" import="java.awt.image.*" import="java.awt.*" import="javax.imageio.*" %> <% // 清空缓冲区 response.reset(); // 注意这里的MIME类型 response.setContentType("image/jpeg"); // 创建一个 640X480 的图像 int width = 640, height = 480; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); // 填充背景 g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); // 绘制文本 g.setColor(Color.RED); // 绘制11条直线 for (int i = 1; i <= 11; i++) { g.drawLine(10, 10, 90, i * 10); } // 绘制1个三角形 g.drawLine(160, 10, 110, 110); g.drawLine(160, 10, 210, 110); g.drawLine(110, 110, 210, 110); // 绘制1个矩形 g.drawLine(230, 10, 230, 110); g.drawLine(230, 10, 330, 10); g.drawLine(330, 10, 330, 110); g.drawLine(230, 110, 330, 110); g.setFont(new Font("方正粗宋简体", Font.PLAIN, 25)); g.drawString("JSP Web图表的绘制", 45, 145); // 部署图形 g.dispose(); // 利用ImageIO类的write方法对图像进行编码 ServletOutputStream sos = response.getOutputStream();//出错行 ImageIO.write(image, "JPG", sos); sos.close(); %>
问题补充:
以上代码在保存为jsp文件 可以在tomcat环境中 正确显示
可是一旦放入eclipse环境中就会提示那个错误
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你必须从java API导入JavascriptExecuter类。 那么你的错误将被纠正。 希望能帮助到你 you have to import JavascriptExecuter class from java API. then your error will be rectified. hope it helps
-
从java.io包中导入ByteArrayInputStream ,以便应用程序可以使用不合格的类: import java.io.ByteArrayInputStream; Import ByteArrayInputStream from the java.io package so that the unqualified class is available to the application: import java.io.ByteArrayInputStream;
-
您的web.xml将Web应用程序声明为Servlet 3.1。 ServletOutputStream.setWriteListener(WriteListener)是一个已添加到Servlet 3.1的方法。 你得到的错误: java.lang.AbstractMethodError: javax.servlet.ServletOutputStream.setWriteListener(Ljavax/servlet/WriteListener;)V 说你已经针对Servlet 3.1 jar编译了你的 ...
-
如问题评论中所述,找到了答案。 问题是客户端(TCPMon)而不是代码。 As mentioned in the comments of the question, found the answer. The problem was the client(TCPMon) rather than the code.
-
不,您需要ServletResponse对象。 No, you need the ServletResponse object.
-
创建一个HttpServlet并在doGet()或doPost()方法中创建一个使用ServletOutputStream初始化的ZipOutputStream并直接写入它: resp.setContentType("application/zip"); // Indicate that a file is being sent back: resp.setHeader("Content-Disposition", "attachment;filename=test.zip"); ...
-
<%@ page import="com.export.servlet.ExportQP"%> 您是否将Servlet导入JSP? Servlet不应该导入。 Servlet通常通过HTTP(超文本传输协议)接收和响应来自Web客户端的请求。 它们被Servlet映射名称定义,在您的情况下似乎是ExportQP 。 错误意味着你应该在JSP中有一个名为exportStr的变量 <% String exportStr="Hello World"; %> <%@ page import="com.expor ...
-
正如评论中已经提到的那样,你的问题有点不合理,但我会试着告诉你它是如何工作的。 首先尝试以下方法: @RequestMapping(value = "/function/{functionId}/image.gif", produces = "image/gif") public void getImage(@PathVariable(value = "functionId") String functionId, HttpServletResponse response) throws IOExcepti ...