rzb8412792
2012-12-17 13:36 阅读 282
已采纳

struts2+mysql 二进制流显示问题

我在进行图片上传和显示操作其中,struts2的相关action源码如下

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bphone.action;

import bphone.iservice.IGoodsService;
import bphone.model.Goods;
import com.opensymphony.xwork2.ActionContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author RZB
 */
public class GoodsAction {
    @Autowired
    private IGoodsService goodsService;
    private String phPinpai;
    private String phXinghao;
    private double phJiage;
    private String phXitong;
    private String phWeb;
    private String phRam;
    private String phRom;
    private String phCpu;
    private File phTupian;
    private String phChicun;
    private int phKucun;
    public String GoodsInfo()
    {
        ActionContext ctx=ActionContext.getContext();
        List<Goods> goodsinfo=goodsService.findAll();
        ctx.put("goodsinfolist", goodsinfo);
        return "goods_info";
    }
    public String GoodsDelete()
    {
        ActionContext ctx=ActionContext.getContext();
        goodsService.deleteGoodsInfo(getPhXinghao());
        return "goods_info";
    }
    public String GoodsAdd() throws FileNotFoundException, IOException
    {
        Goods goods=new Goods();
        goods.setPhChicun(getPhChicun());
        goods.setPhCpu(getPhCpu());
        goods.setPhJiage(getPhJiage());
        goods.setPhKucun(getPhKucun());
        goods.setPhPinpai(getPhPinpai());
        goods.setPhRam(getPhRam());
        goods.setPhRom(phRom);
        FileInputStream in=new FileInputStream(getPhTupian());
        byte[] bt=new byte[in.read()];
        goods.setPhTupian(bt);
        goods.setPhWeb(getPhWeb());
        goods.setPhXinghao(getPhXinghao());
        goods.setPhXitong(getPhXitong());
        goodsService.addGoodsInfo(goods);
        return "goods_info";
    }
 ……get和set方法省略,页面显示信息使用的<s:iterator>来显示list内容,但是显示不出来图片,如何才能显示图片呢,请大家指导一下

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    jinnianshilongnian jinnianshilongnian 2012-12-17 14:10

    你需要单独写一个action 然后返回图片的流信息(直接响应返回) 设置mime类型为图片的

    点赞 评论 复制链接分享

相关推荐