turn:
js file, how to use EL expressions to obtain values
Original approach is the introduction of the first document in the jsp page
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <c:set var="ctxStatic" value="${pageContext.request.contextPath}/static" /> <c:set var="ctx" value="${pageContext.request.contextPath}"/>
Js file is then used in the inside using the $ {ctx}, is the direct result of the output, and is not parsed, javascript client is executed, the EL is performed on the server side rather than the client before the server performs, so to get any value .
Because it is a separate js code is out of the file, and then introduced to the jsp page. Now we can advance in the global variable defined js jsp page to resolve.
<script type="text/javascript">
var ctx = "${ctx}";
</script>
We can then be used directly in the js code ctx introduced, the easy access to the desired value.
Original approach is the introduction of the first document in the jsp page
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <c:set var="ctxStatic" value="${pageContext.request.contextPath}/static" /> <c:set var="ctx" value="${pageContext.request.contextPath}"/>
Js file is then used in the inside using the $ {ctx}, is the direct result of the output, and is not parsed, javascript client is executed, the EL is performed on the server side rather than the client before the server performs, so to get any value .
Because it is a separate js code is out of the file, and then introduced to the jsp page. Now we can advance in the global variable defined js jsp page to resolve.
<script type="text/javascript">
var ctx = "${ctx}";
</script>
We can then be used directly in the js code ctx introduced, the easy access to the desired value.