src控件

@RequestMapping要么用@ResponseBody(写入responsebody中)阻止跳转,要么用写入response中,阻止跳转,写入response中相当于jsp页面(临时生成的即动态jsp页面)
//
src控件,要么指向一个静态的页面,页面中写值,要么返回动态页面,src会自动把写的值读出:jsp的文本,jsp的图片(二进制流)


静态:
dwz的选择框:
<select class="combox" name="province" ref="w_combox_city" refUrl="demo/combox/city_{value}.html">
<option value="all">所有省市</option>
<option value="bj">北京</option>
<option value="sh">上海</option>
<option value="zj">浙江省</option>
</select>
<select class="combox" name="city" id="w_combox_city" ref="w_combox_region" refUrl="demo/combox/region_{value}.html">
<option value="all">所有城市</option>
</select>
<select class="combox" name="region" id="w_combox_region">
<option value="all">所有区县</option>
</select>


city_all.html:
[
    ["all", "请选择省份"]
]
city_sh.html:

[
["sh", "上海市"]
]


动态页面,Java动态写入:

<p>
<label>商品种类:</label>
<select class="combox" name="warekind_key" ref="spsxKey" refUrl="${applicationScope.contextPath}/tbBasSpsxValue/spsxList?spsxValueKey={value}">
<option value="" selected="selected">===全部===</option>
<c:forEach var="item" items="${basbed}" varStatus="s">
<option value="${item.ware_key}"
<c:if test="${item.ware_key==vo.wareKey}">selected="selected"</c:if>>
${item.ware_name}</option>
</c:forEach>
</select>
</p>
<p>
<label>属性项:</label>
<select class="combox"  name="spsxKey" id="spsxKey">
    <option value="-1">===请选择===</option>
    </select>
</p>




后台java:

@RequestMapping("/tbBasSpsxValue/spsxList")
// @ResponseBody
public void  spsxList(@RequestParam(value = "spsxValueKey", required = false) long spsxValueKey,
            HttpServletRequest request,HttpServletResponse response,Model model) throws EsteelException {
  response.setCharacterEncoding("UTF-8");
List<TbBasSpsxTltnVo> tbBasSpsxTltns = new ArrayList<TbBasSpsxTltnVo>();
JSONArray json = new JSONArray();
if(!"".equals(spsxValueKey)){
TbBasSpsxTltn tbBasSpsxTltn = new TbBasSpsxTltn();
tbBasSpsxTltn.setWareKey(BigDecimal.valueOf(spsxValueKey));
tbBasSpsxTltns=  tbBasSpsxValueService.getlistVo(spsxValueKey+"");
JSONObject jo1 = new JSONObject();
            jo1.put("-1", "==请选择类型==");
            json.put(jo1);
            for(TbBasSpsxTltnVo a : tbBasSpsxTltns){
                JSONObject jo = new JSONObject();
                jo.put(a.getSpsxKey()+"", a.getSpsxName());
                json.put(jo);
            }
}
System.out.println(json.toString().replace("{", "[").replace("}", "]").replace(":", ","));
try {
response.getWriter().write(json.toString().replace("{", "[").replace("}", "]").replace(":", ","));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// return json.toString();
}


再如图片的控件:

<div id="preview"><img id="imghead" src="${pageContext.request.contextPath}/basBed/showImage?imageType=bas&id=${vo.ware_key}" alt=""  style="cursor: pointer;width: 100%;" /></div>



@RequestMapping(value = "/basBed/showImage")
    public void showReportImage(@RequestParam(value = "imageType") String imageType,
                                @RequestParam(value = "id") Long id,
                                HttpServletRequest request,HttpServletResponse response) throws IOException, NumberFormatException, EsteelException {
//              response.setContentType("image/jpeg");

            response.setCharacterEncoding("UTF-8");
//         String filePath= WebConfig.get("filePath");
            String path = WebConfig.get("filePath") ;
        File file=null;
        TbBasBed currbasBed = new TbBasBed();
currbasBed.setWare_key(id);
currbasBed= tbBasBedService.getBasBedById(Integer.valueOf(id+""));
        if(currbasBed!=null){
            if("bas".equals(imageType)&&currbasBed.getPicture_address()!=null){
            file=new File(path+currbasBed.getPicture_address());
            }
        }
        if( file==null||!file.exists()){
                response.getWriter().print("未找到图片");
        }else {
            response.setContentType("image/jpeg");
            FileInputStream fos = new FileInputStream(file);
            byte[] bytes = new byte[1024*1024];
            int length = 0;
            while((length=fos.read(bytes))!=-1){
                response.getOutputStream().write(bytes,0,length);
            }
        }
    }

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2302388