jsp页面执行java语法,获取的值在页面调用

时间:2023-03-09 20:46:56
jsp页面执行java语法,获取的值在页面调用
  1. 首先在页面头引用用到类的包路径
  2. 写需要执行的java语法
  3. 页面转换引用
<!-- 引用包路径 -->
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.inspur.icpmg.systemMg.vo.UserEntity"%>
<%@ page language="java" import="com.inspur.icpmg.itss.asset.service.AssetService"%>
<%@ page language="java" import="com.inspur.icpmg.itss.asset.service.AssetServiceImp"%>
<%@ page language="java" import="com.inspur.icpmg.util.WebLevelUtil" %>
<%@ page language="java" import="com.inspur.icpmg.itss.asset.service.AssetInventoryServiceImp" %> <!-- 执行java语法 -->
<%
UserEntity user = WebLevelUtil.getUser(request);
String online = user.getUname();
AssetInventoryServiceImp service = new AssetInventoryServiceImp();
String cloudcenterid = service.getcloudcenterIdByCityid(user.getCityid());
%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/web/inc.jsp"></jsp:include>
<title>xxxx</title>
</head> <body> <!-- 转换 -->
<script>
$(document).ready(function() {
cloudcenterid = '<%=cloudcenterid%>';
onlineUser = '<%=online%>';
}); <!-- 使用 -->
$('#onlineUser').val(onlineUser);
</script> <input type="text" id="onlineUser"/>