<%@page import="java.awt.*"%>
<%@page import="java.awt.image.*"%>
<%@page import="com.sun.image.codec.jpeg.*"%>
<%@page import="javax.imageio.*" %>
public static void addPhotoFrame (String framPicName, String srcPicName, String outputPicName) throws Exception {
//相框文件
File framePicFile = new File(framPicName);
Image framePic = ImageIO.read(framePicFile);
int width = framePic.getWidth(null);
int height = framePic.getHeight(null);
BufferedImage image=new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
g.drawImage(framePic, 0, 0, width, height, null);
//原图片文件
File srcPicFile = new File(srcPicName);
Image srcPic = ImageIO.read(srcPicFile);
int srcWidth = srcPic.getWidth(null);
int srcHeight = srcPic.getHeight(null);
g.drawImage(srcPic, 0, 6, srcWidth, srcHeight, null);
g.dispose();
FileOutputStream out = new FileOutputStream(outputPicName);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
addPhotoFrame("2.jpg","1.jpg","3.jpg");

解决方案 »

  1.   

    沙发抢下来,报错的代码是:org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 328 in the jsp file: /pages/month/cardChannel.jsp
    The type List is ambiguous
    325: String verify_rlt = element.getChild("Verify_rlt").getText();
    326:             String photo = element.getChild("Photo").getText();
    327: String photot = element.getChild("Photot").getText();
    328: List photos = element.getChildren("Photos");
    329:             for(int i = 0; i< Integer.valueOf(photot).intValue(); i++){
    330:             Element photoString=(Element)photos.get(i);
    331: String pStr = photoString.getText();
    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)328行是什么原因导致的???
      

  2.   

    Unable to compile class for JSP:1.
      原因是编译器不没jre或者不对。
    2.
      tomcat 中 指定jre
      

  3.   

    The type List is ambiguous List 类型不清楚
      

  4.   

    jsp文件全部贴上来吧,否则没法看
      

  5.   

    328: List photos = element.getChildren("Photos"); 有问题
      

  6.   

    用java.util.List photos = element.getChildren("Photos"); 试试吧。
      

  7.   


    我说哥们你的代码是在jsp 在运行的吗?
    看这个<%@page import="java.awt.*"%>
    <%@page import="java.awt.image.*"%>
    <%@page import="com.sun.image.codec.jpeg.*"%>
    <%@page import="javax.imageio.*" %>
    应该是在jsp吧。
    可是下面的方法也应该加上<%!
    %>吧。
      

  8.   

    <%@page import="java.awt.*"%>
    <%@page import="java.io.*"%>
    <%@page import="java.awt.image.*"%>
    <%@page import="com.sun.image.codec.jpeg.*"%>
    <%@page import="javax.imageio.*" %>
    <%@page import="java.awt.*"%>
    <%@page import="java.util.*"%>
    <%!
    public static void addPhotoFrame (String framPicName, String srcPicName, String outputPicName) throws Exception {
    //相框文件
    File framePicFile = new File(framPicName);
    Image framePic = ImageIO.read(framePicFile);
    int width = framePic.getWidth(null);
    int height = framePic.getHeight(null);
    BufferedImage image=new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.createGraphics();
    g.drawImage(framePic, 0, 0, width, height, null);
    //原图片文件
    File srcPicFile = new File(srcPicName);
    Image srcPic = ImageIO.read(srcPicFile);
    int srcWidth = srcPic.getWidth(null);
    int srcHeight = srcPic.getHeight(null);
    g.drawImage(srcPic, 0, 6, srcWidth, srcHeight, null);
    g.dispose();
    FileOutputStream out = new FileOutputStream(outputPicName);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(image);
    out.close();
    }
    %>
    <%
    addPhotoFrame("2.jpg","1.jpg","3.jpg");
    %>都有加的,代码就是这样,运行下报的错
      

  9.   


    上面说的对啊, 很明显 错误提示 就是List没有导入的嘛;或是直接在最上面导入也行:
    <%@page import="java.util.List"%> 
      

  10.   

    晕了 /pages/month/cardChannel.jsp 
    是你贴出来的那个JSP页面吗
      

  11.   

    An error occurred at line: 328 in the jsp file: /pages/month/cardChannel.jsp The type List is ambiguous 好像在你贴出来的JSP页面里面都没有 List 的哦
      

  12.   


    我就是不想大家混淆了我代码,所以单独调用出来这个方法做测试test.jsp页面