jsp中调用Java
0,导入包
1,获取容器中的对象
2,全局变量
3,执行<%%>,执行并返回<%=%>(随处可写)
4,所有<%%>代码可合看一体
5,<%%>里面不可套用el表达式
比如<input type="hidden" id="jgdw${st.index}" value="<%=cha.getDictValue("CURRENCY_TYPE_UNIT", ${dataMap.CURRENCY_TYPE})%>/${item.PRICE_UNIT2_CN}">
这种可以:
<input type="hidden" id="jgdw${st.index}" value="<%=cha.getDictValue("CURRENCY_TYPE_UNIT","B")%>/${item.PRICE_UNIT2_CN}">
示例:
@Controller
public class ChatController extends BaseController {
@Autowired
TbConObjService tbConObjService;
@Autowired
TbConOrdService tbConOrdService;
@Autowired
TbConOrdPriceService tbConOrdPriceService;
@Autowired
TbCusFirmService tbCusFirmService;
@Autowired
MessageSender topicSender;
@Autowired
TbCusUserService tbCusUserService;
@Autowired
VwDataAllallService vwDataAllallService;
@RequestMapping(value = "/chat/offer/getDictValue")
public String getDictValue(String currencyType ,String nowType) throws EsteelException, UnsupportedEncodingException {
Map param = new HashMap<String,Object>();
param.put("business_type", currencyType);
param.put("lookup_type", nowType);
List<Map> map = tbConObjService.getDictValue(param);
if(map!=null&&map.size()>0){
return map.get(0).get("LOOKUP_NAME")+"";
}else{
return "";
}
}
}
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/include.inc.jsp"%>
<%@page import="com.esteel.chat.controller.*" %>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%
response.setHeader("P3P","CP=CAO PSA OUR");
ServletContext context = request.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
ChatController cha= (ChatController)ctx.getBean("chatController");
String dw= cha.getDictValue("CURRENCY_TYPE_UNIT", "B");
%>
<c:import url="../common/pagerForm.jsp"></c:import>
<label for="" class="c_ul_label w80 tr">询盘价格:</label>
<input type="hidden" id="jgdw${st.index}" value="<%=cha.getDictValue("CURRENCY_TYPE_UNIT", "B")%>/${item.PRICE_UNIT2_CN}">