相关文章
更多最近更新
更多jsp中使用JavaBean出现“引用类不可用”
2019-03-25 13:36|来源: 网路
do_upload.jsp
PicRgb
当使用up_load.jsp页面时 出现错误
提示 useBean使用的类不可用……弄了一下午,头都大了 - -
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB2312"%> <%@ page import="org.apache.commons.fileupload.*"%> <%@ page import="org.apache.commons.fileupload.servlet.*"%> <%@ page import="org.apache.commons.fileupload.disk.*"%> <%@ page import="java.util.*"%> <%@ page import="java.io.*"%> <%@ page import="picDeal.*" %> <jsp:useBean id="pic" scope="page" class="picDeal.PicRgb"> </jsp:useBean> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> <title>文件上传</title> </head> <body> <center>上传中.....</center> <% String uploadPath=application.getRealPath("/upload"); String picName=null; int width=0,height=0; //目标文件夹的路径必须使用绝对路径,不能用相对路径 boolean isMultipart = ServletFileUpload.isMultipartContent(request); if(isMultipart==true){ try{ FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request);//得到所有的文件 Iterator<FileItem> itr = items.iterator(); while(itr.hasNext()){//依次处理每个文件 FileItem item=(FileItem)itr.next(); String fileName=item.getName();//获得文件名,包括路径 if(fileName!=null) { File fullFile=new File(item.getName()); picName=fullFile.getName(); File savedFile=new File(uploadPath,fullFile.getName()); item.write(savedFile); } } out.println("upload succeed!"); out.println("上传的图片如下:"); //分析图片, 获取图片的信息 pic.setData(picName); session.setAttribute("picture",pic); %> <form action="anaresult.jsp" method="post"> <table> <tr> <td>上传的图片如下:</td> </tr> <tr> <td><img src=<%= "upload/"+picName %>></td> </tr> <tr> <td><input type="submit" name="submit" value="提交分析"></td> </tr> </table> </form> <% } catch(Exception e){ e.printStackTrace(); out.print("failed!"); } } else{ out.println("the enctype must be multipart/form-data"); } %> </body> </html>
PicRgb
package picDeal; import java.awt.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; public class PicRgb { private int []rData; private int []gData; private int []bData; private int width; private int height; //分析图片,参数为图片的名字 public PicRgb() { } public void setData(String name){ Image image=null; try{ File sourceimage = new File("upload/"+name); image=ImageIO.read(sourceimage); } catch(IOException e){ } //读取图像的高度&宽度 this.width=image.getWidth(null); this.height=image.getHeight(null); System.out.println(width); System.out.println(height); //读取图片像素信息 Image im=Toolkit.getDefaultToolkit().getImage("upload/"+name); this.rData=new int[256]; this.gData=new int[256]; this.bData=new int[256]; int []pixels=new int[width*height]; try{ PixelGrabber pg=new PixelGrabber(im,0,0,width,height,pixels,0,width); pg.grabPixels(); }catch(InterruptedException e){ e.printStackTrace(); } ColorModel cm=ColorModel.getRGBdefault(); int red,green,blue; for(int i=0;i<width*height;i++){ red=cm.getRed(pixels[i]); this.rData[red]++; green=cm.getGreen(pixels[i]); this.gData[green]++; blue=cm.getBlue(pixels[i]); this.bData[blue]++; } } public void setRData(int[] r) { this.rData=r; } public void setGData(int[] g) { this.gData=g; } public void setBData(int[] b) { this.bData=b; } public void setWidth(int w) { this.width=w; } public void setHeight(int h) { this.height=h; } public int getWidth() { return this.width; } public int getHeight() { return this.height; } public int[] getRData() { return this.rData; } public int[] getGData() { return this.gData; } public int[] getBData() { return this.bData; } }
当使用up_load.jsp页面时 出现错误
提示 useBean使用的类不可用……弄了一下午,头都大了 - -
相关问答
更多-
学习jsp servelet javabean,mvc[2021-05-15]
jsp,网上有很多教程 我的博客里面也有 http://yulin.jsjjz.com -
如何使用javabean和使用javabean的优势[2023-08-21]
区别就是jsp中不再有大量的JAVA代码 使前后台分工更明确 也使程序编写更容易 维护更容易 -
来自javabean的JSP分页(JSP pagination from javabean)[2022-02-17]
快速简单的答案,使用此: http://www.datatables.net/ 这是一个可爱的可滚动/分页表,它有第三方插件,允许编辑。 这很容易设置,网站上有很多例子和一个活跃而有用的论坛。 从数据库的角度来看,您需要考虑接受以下参数到您的查询: 每页行数 当前页面 我公司的DBA将其拆分为两个我需要调用的查询: 给我第1页的所有值,每页10行。 给我可能的最大页数(实际上不返回任何值。) Quick and simple answer, use this: http://www.datatables.n ... -
forward发现MyJsp.jsp但url->请求的资源不可用(forward finds MyJsp.jsp but url-> The requested resource is not available)[2022-08-26]
嗯,这是设计的 。 出于安全原因,tomcat(也不是任何其他servlet或Java EE容器)不应该允许响应/WEB-INF下的文件的直接请求,在这里您可以找到目录classes和libs 。 通常在/WEB-INF下放置只能通过另一个servlet转发的jsp文件。 Well, it is by design. For security reasons, tomcat (nor any other servlet or Java EE container) should not allow respo ... -
csp资源在jsp中不可用(Css resource not available in jsp)[2022-08-21]
我通过将此问题添加到我的web.xml来解决了这个问题default /resources/* default ... -
由于您使用的是eclipse,因此您可以创建War文件并将其部署到服务器机器的tomcat / webapps文件夹中。 重新启动Tomcat服务器并让tomcat自动加载您的应用程序。 yourProject(Right Click)->export->web->war 选择项目,提供要生成的war文件的名称。 注意 :您的应用程序上下文与您的War文件名相同。 通过这种方式,您可以避免由于直接文件传输而发生的任何错误。 我注意到的另一件事是你使用你的动作URL作为/MyProject/Servlet 。 ...
-
JSP中的Javabean属性(Javabean property in JSP)[2023-05-22]
我不知道你做了什么但是因为你有一个带有3个实例变量fname, lname, email的bean。 你必须拥有getter and setters 。 然后在jsp中,您必须首先设置属性的值。超类'方法不可用(superclass' methods not available)[2022-01-11]
从UI5文档: 如果从具有( 或可能获得 )init()方法的另一个控件继承,则需要显式调用它... 由于Button控件到目前为止还没有init()函数(但在将来的版本中可以存在),我会这样做,以便将来安全: if (sap.ui.commons.Button.prototype.init) { // check whether superclass has an init() method sap.ui.commons.Button.prototype.init.apply(this, arg ...JSP,javabean和mysql(JSP , javabean and mysql)[2022-12-02]
你最有可能将你的类命名为 Java EE 6与Glassfish 3 书。 小心你如何命名你的路径。 编译器找不到 Book类。 You've most likely named your classes like the ones in the Java EE 6 With Glassfish 3 book. Be careful on how you name your paths. The compiler cannot find the Book class.将Fede的评论作为社区维基回答发布。 如果Fede发布他自己的答案,请删除。 Fede表示: GestionCasinoEntities类是否在一个不同于试图使用它的程序GestionCasinoEntities定义? 如果是这种情况, 您还需要向引用项目添加引用EntityFramework.dll ,尽管编译器应该已经警告过您。 Posting Fede's comment as a community wiki answer. Please delete, if Fede posts his own ...