java.security.AccessControlException: access denied (java.lang.RuntimePermission
权限

解决方案 »

  1.   

    我知道为了安全,applet在读取文件这些地方会有些限制,可是不知道是具体哪里受限,比较此例中读取的是本机的图片,而且,显示窗口中也有图片显示,为什么还会有权限控制异常呢?另外,是不是使用了applet的类的应用程序也有这个限制呢?在应用程序中要如何才可以读取图片呢?
    会的来帮忙啊。第一次来这里求助,是不是分太少了啊。我马上改到100啊。
      

  2.   

    类似这样访问:
    new ImageIcon( ImageIconFactory.class.getClassLoader().getResource( "resource/images/saveas.gif" ) );
      

  3.   

    谢谢先
    现用jsp写了如下程序,图片可以读出来了,但是。此程序在参数为汉字的时候却打出问号来了。。不知道哪里编码解码出错了,如果在程序中直接给要输出的变量赋值(汉字),那么就会显示正常。有兴趣的朋友来试试。
    ----------------------------------------------------------------
    访问方式类似:http://localhost/1.jsp?name=%B1%FD%BE%ED%B4%D0
    ----------------------------------------------------------------
    <%@ page contentType="image/jpeg" import="java.awt.*,java.awt.Graphics2D,java.io.File,java.awt.image.*,java.util.*,javax.imageio.*" %><% 
    //设置页面不缓存 text/html;charset=GB2312
    response.setHeader("Pragma","No-cache"); 
    response.setHeader("Cache-Control","no-cache"); 
    response.setDateHeader("Expires", 0); String name = request.getParameter("name");
    try
    {
    if(name!= null && name.length() > 1) name = new String(name.getBytes("ISO-8859-1"),"GB2312");
    else name = "";
    }
    catch(Exception e)
    {
    //out.println(e.toString());
    }File _file = new File("h:/bean/1.jpg");
    Image img = null;
    int w = 10;
    int h = 10;
    try
    {
    img = javax.imageio.ImageIO.read(_file);
    w = img.getWidth(null);
    h = img.getHeight(null);
    }
    catch(Exception e)
    {
    //out.println(e.toString());
    }// 在内存中创建图象 
    int width=w, height=h; 
    int flen = 0;
    if(name != null && name.length() > 0)
    {
    flen = name.length();
    }
    if(flen > 3) flen = 3;
    int fx[] = new int[flen];
    int fy[] = new int[flen];
    String names[] = new String[flen];
    int fx0 = 45;
    int fy0 = 174;
    int fx2 = 47; //字的位置
    int fy2 = 224;
    switch(flen)
    {
    case 1:
    fx[0] = fx0 + 1;
    fy[0] = fy0 + 30;
    if(name != null && name.length() == 1) names[0] = name.substring(0,1);
    break;
    case 2:
    fx[0] = fx0;
    fy[0] = fy0;
    fx[1] = fx0;
    fy[1] = fy0 + 50;
    if(name != null && name.length() == 2)
    {
    names[0] = name.substring(0,1);
    names[1] = name.substring(1,2);
    }
    break;
    case 3:
    fx[0] = fx0;
    fy[0] = fy0;
    fx[1] = fx0;
    fy[1] = fy0 + 30;
    fx[2] = fx0;
    fy[2] = fy0 + 60;
    if(name != null && name.length() == 3)
    {
    names[0] = name.substring(0,1);
    names[1] = name.substring(1,2);
    names[2] = name.substring(2,3);
    }
    break;
    default:
    flen = 0;
    break;
    }
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // 获取图形上下文 
    Graphics g = image.getGraphics();
    Graphics2D g2 = (Graphics2D)image.getGraphics();if(img !=null) g.drawImage(img,0,0,null);if(flen > 0)
    {
    //设定字体
    g2.setColor(new Color(100,58,0)); 
    g2.setFont(new Font("KaiTi_GB2312",Font.BOLD,24));
    g2.rotate(-0.25,fx0 + 1,fy0);
    for(int i = 0;i < flen; i++)
    {
    try
    {
    if(names.length > i)
    {
    //out.println(names[i]);
    //g2.drawString(new String(str.getBytes("GB2312"),"ISO-8859-1"),fx[i],fy[i]);
    g2.drawString(new String(names[i].getBytes("ISO-8859-1"),"GB2312"),fx[i],fy[i]);
    }
    }
    catch(Exception e)
    {
    out.println(e.toString());
    }
    }
    }
    // 图象生效 
    g.dispose(); // 输出图象到页面 
    ImageIO.write(image, "JPEG", response.getOutputStream()); 
    %>
      

  4.   

    程序解决了,最后的程序如下,查看效果地址是:http://ivyziran.cnlife.net/jt.html?name=%B1%FD%BE%ED%B4%D0
    ----------------------------------
    <%@ page contentType="image/jpeg" import="java.awt.*,java.awt.Graphics2D,java.io.File,java.awt.image.*,java.util.*,javax.imageio.*" %><% 
    //设置页面不缓存 text/html;charset=GB2312
    response.setHeader("Pragma","No-cache"); 
    response.setHeader("Cache-Control","no-cache"); 
    response.setDateHeader("Expires", 0); String name = request.getParameter("name");
    try
    {
    if(name!= null && name.length() > 0) name = new String(name.getBytes("ISO-8859-1"),"GB2312");
    else name = "";
    }
    catch(Exception e)
    {
    //out.println(e.toString());
    }File _file = new File("h:/bean/1.jpg");
    Image img = null;
    int w = 10;
    int h = 10;
    try
    {
    img = javax.imageio.ImageIO.read(_file);
    w = img.getWidth(null);
    h = img.getHeight(null);
    }
    catch(Exception e)
    {
    //out.println(e.toString());
    }// 在内存中创建图象 
    int width=w, height=h; 
    int flen = 0;
    if(name != null && name.length() > 0)
    {
    flen = name.length();
    }
    if(flen > 3) flen = 3;
    int fx[] = new int[flen];
    int fy[] = new int[flen];
    String names[] = new String[flen];
    int fx0 = 48;
    int fy0 = 174;
    switch(flen)
    {
    case 1:
    fx[0] = fx0 + 1;
    fy[0] = fy0 + 30;
    names[0] = name.substring(0,1);
    break;
    case 2:
    fx[0] = fx0;
    fy[0] = fy0;
    fx[1] = fx0;
    fy[1] = fy0 + 50;
    if(name != null && name.length() == 2)
    {
    names[0] = name.substring(0,1);
    names[1] = name.substring(1,2);
    }
    break;
    case 3:
    fx[0] = fx0;
    fy[0] = fy0;
    fx[1] = fx0;
    fy[1] = fy0 + 30;
    fx[2] = fx0;
    fy[2] = fy0 + 60;
    if(name != null && name.length() == 3)
    {
    names[0] = name.substring(0,1);
    names[1] = name.substring(1,2);
    names[2] = name.substring(2,3);
    }
    break;
    default:
    flen = 0;
    break;
    }
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // 获取图形上下文 
    Graphics g = image.getGraphics();
    Graphics2D g2 = (Graphics2D)image.getGraphics();if(img !=null) g.drawImage(img,0,0,null);if(flen > 0)
    {
    //设定字体
    g2.setColor(new Color(100,58,0)); 
    g2.setFont(new Font("KaiTi_GB2312",Font.BOLD,24));
    g2.rotate(-0.25,fx0 + 1,fy0);
    for(int i = 0;i < flen; i++)
    {
    try
    {
    if(names.length > i)
    {
    //out.println(names[i]);
    //g2.drawString(new String(str.getBytes("GB2312"),"ISO-8859-1"),fx[i],fy[i]);
    g2.drawString(names[i],fx[i],fy[i]);
    }
    }
    catch(Exception e)
    {
    out.println(e.toString());
    }
    }
    }
    // 图象生效 
    g.dispose(); // 输出图象到页面 
    ImageIO.write(image, "JPEG", response.getOutputStream()); 
    %>-------------------------------
    好了,结贴。谢谢来关注的兄弟