我想做的是在页面中用html中的img中的src地址来返回一个图片地址
就是想在邮件的附件里嵌入代码 根据不同的参数返回不同的图片
虽然我用io流的形式可以实现
但是 我想要更好一点的方法 可不可在请求的action中将地址定向到相应的图片地址

解决方案 »

  1.   

    应该可以啊,只要你的参数是有规则的,在action里面根据参数把图片直接打印出来不就可以了
    也就是说action里面就不转向了,直接打印出结果,
      

  2.   

    <img src="http://*****/*.do?cid=435">
    让这样的代码显示出图片
    在*.do的action中如何返回地址让src的地址转到图片的地址。如果要在action中打印的话用response.getWriter().println()吗?
    只是打印了地址
      

  3.   

    别打印地址啊,你如果想在<img 中用,应该是要打印图片流吧
    我用应用程序试过,可以把图片打印到程序上面,而不是插入图片
    html中没有试过,你可以试一下,
      

  4.   

    从图片文件中读取数据流,再到程序上打印出来,
    html中我不知道行不行,不过大概是这个思路吧,
      

  5.   

    .
    CLASSPATH=C:\bea\JDK141~1\lib\tools.jar;C:\bea\WEBLOG~1\server\lib\weblogic_sp.j
    ar;C:\bea\WEBLOG~1\server\lib\weblogic.jar;C:\bea\WEBLOG~1\server\lib\ojdbc14.ja
    r;C:\bea\WEBLOG~1\common\eval\pointbase\lib\pbserver44.jar;C:\bea\WEBLOG~1\commo
    n\eval\pointbase\lib\pbclient44.jar;C:\bea\JDK141~1\jre\lib\rt.jar;C:\bea\WEBLOG
    ~1\server\lib\webservices.jar;
    .
    PATH=C:\bea\WEBLOG~1\server\bin;C:\bea\JDK141~1\jre\bin;C:\bea\JDK141~1\bin;C:\P
    rogram Files\Java\jdk1.5.0\bin;C:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1
    .3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINDOWS\system32;C:\WINDOWS;C:
    \WINDOWS\System32\Wbem;C:\bea\WEBLOG~1\server\bin\oci920_8
    .
    ***************************************************
    *  To start WebLogic Server, use a username and   *
    *  password assigned to an admin-level user.  For *
    *  server administration, use the WebLogic Server *
    *  console at http:\\[hostname]:[port]\console    *
    ***************************************************
    <2006-12-15 下午13时16分10秒 CST> <Info> <WebLogicServer> <BEA-000377> <Starting
     WebLogic Server with Java HotSpot(TM) Client VM Version 1.4.1_05-b01 from Sun M
    icrosystems Inc.>
    <2006-12-15 下午13时16分10秒 CST> <Info> <Configuration Management> <BEA-150016>
     <This server is being started as the administration server.>
    <2006-12-15 下午13时16分10秒 CST> <Info> <Management> <BEA-141107> <Version: Web
    Logic Server 8.1 SP2  Mon Nov 17 22:57:23 PST 2003 311144
    WebLogic XMLX Module 8.1 SP2  Mon Nov 17 22:57:23 PST 2003 311144 >
    <2006-12-15 下午13时16分10秒 CST> <Notice> <Management> <BEA-140005> <Loading do
    main configuration from configuration repository at C:\bea\user_projects\domains
    \Tlinkdomain\.\config.xml.>
    <2006-12-15 下午13时16分16秒 CST> <Notice> <Log Management> <BEA-170019> <The se
    rver log file C:\bea\user_projects\domains\Tlinkdomain\myserver\myserver.log is
    opened. All server side log events will be written to this file.>
    <2006-12-15 下午13时16分19秒 CST> <Notice> <Security> <BEA-090082> <Security ini
    tializing using security realm myrealm.>
    <2006-12-15 下午13时16分20秒 CST> <Notice> <WebLogicServer> <BEA-000327> <Starti
    ng WebLogic Admin Server "myserver" for domain "Tlinkdomain">
    <2006-12-15 下午13时16分29秒 CST> <Warning> <HTTP> <BEA-101248> <[Application: '
    C:\bea\user_projects\domains\Tlinkdomain\applications', Module: 'tlink']: Deploy
    ment descriptor "web.xml" is malformed. Check against the DTD: org.xml.sax.SAXPa
    rseException: cvc-elt.1: Cannot find the declaration of element 'web-app'. (line
     4, column 105).>
    <2006-12-15 下午13时16分54秒 CST> <Warning> <HTTP> <BEA-101247> <Application: 'C
    :\bea\user_projects\domains\Tlinkdomain\applications', Module: 'display': Public
     ID references the old version of the Servlet DTD. You must change the public ID
     in web.xml file to "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN".>
    <2006-12-15 下午13时16分55秒 CST> <Warning> <HTTP> <BEA-101195> <[ServletContext
    (id=10708849,name=display,context-path=/display)] Could not resolve TLD from the
     given location "/WEB-INF/displaytag-11.tld".>
    log4j:WARN No appenders could be found for logger (org.apache.struts.util.Proper
    tyMessageResources).
    log4j:WARN Please initialize the log4j system properly.
    <2006-12-15 下午13时17分05秒 CST> <Notice> <WebLogicServer> <BEA-000331> <Starte
    d WebLogic Admin Server "myserver" for domain "Tlinkdomain" running in Developme
    nt Mode>
    <2006-12-15 下午13时17分05秒 CST> <Notice> <WebLogicServer> <BEA-000360> <Server
     started in RUNNING mode>
    <2006-12-15 下午13时17分05秒 CST> <Notice> <WebLogicServer> <BEA-000355> <Thread
     "ListenThread.Default" listening on port 7002, ip address *.*>
    java.net.SocketException: Connection reset by peer: socket write error
            at java.net.SocketOutputStream.socketWrite0(Native Method)
            at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
            at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
            at weblogic.servlet.internal.ChunkUtils.writeChunkTransfer(ChunkUtils.ja
    va:247)
            at weblogic.servlet.internal.ChunkUtils.writeChunks(ChunkUtils.java:223)        at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:296)
            at weblogic.servlet.internal.ChunkOutputWrapper.flush(ChunkOutputWrapper
    .java:144)
            at weblogic.servlet.internal.ServletOutputStreamImpl.flush(ServletOutput
    StreamImpl.java:126)
            at com.tlink.chat.room.action.FkdlAction.execute(FkdlAction.java:98)
            at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
    tProcessor.java:419)
            at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
    va:224)
            at org.apache.struts.action.ActionServlet.process(ActionServlet.java:119
    4)
            at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
    (ServletStubImpl.java:971)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:402)
            at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
    va:27)
            at com.tlink.chat.tool.DlFilter.doFilter(DlFilter.java:40)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
    va:27)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:6356)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
    dSubject.java:317)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
    118)
            at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3635)
            at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2585)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
    代码为  
    ServletOutputStream out = response.getOutputStream();
    String filePath = this.getServlet().getServletContext().getRealPath("/");
    System.out.println(filePath);
    StringBuffer tempStr = new StringBuffer();
    tempStr.append(filePath);
    tempStr.append("\\images\\");
    tempStr.append("1_online.gif");
    File f=new File(tempStr.toString());
    FileInputStream in=new FileInputStream(f);
    byte b[] = new byte[20004];
    int i=0;
    while((i = in.read(b, 0, b.length)) >=0){
    out.write(b);
    out.flush();
    out.close(); 
    }
      

  6.   

    你用脚本动态修改img的src不就可以了吗?汗
      

  7.   

    io的时候,不用产生文件File对象,直接使用out输出2进制流数组就可以了,你可以google下jsp 动态验证码,参考下
      

  8.   

    out输出2进制流数组如何得到不会啊验证码那里是用画出的 我要读特定的图片
    只是根据不同参数选择不同的图片
      

  9.   

    一样的啊~人家使用2dapi画的验证码,你用路径去读文件就是了啊