<%@page import="action.UserBean"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index1.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%-- //el使用 ${pageScope.name}、${param.name}、${$requestScope.name}、${$sessionScope.name}、${$applicationScope.name}
ognl使用<s:peroperty value="#attr.name"/>
<s:property value="#parameters.name"/>
<s:property value="#request.name"/>
<s:property value="#session.name"/>
<s:property value="#application.name"/>
<s:textfield name="name" value="%{#parameters.name}"/>
说明,attr 如果可以访问到,则访问 pageContext,否则将 依次搜索 pageContext、request、session、application 相应值,所以可用来访问 pageContext 中的值,可替代 EL 的 ${pageScope.name}。
--%>
<s:set value="name" var="name1"/>
<s:property value="name1"/> ongl直接接收action<br/>
<c:set value="${name1 }" var="name2" scope="page"></c:set>
<c:out value="${name }"></c:out> jstl直接接收action<br/>
${name } el直接接收action<br/>
<%=request.getAttribute("name") %> java直接接收action<br/>
<c:out value="${name2 }"></c:out> jstl接收ognl<br/>
${name2 } el接收jstl<br/>
${name1 } el接收ognl<br/>
<%=pageContext.getAttribute("name2") %> java接收jstl<br/>
<%int i=12345;//jstl el ognl无法直接取到
%>
<%=i %> java重新定义变量i<br/>
无法直接接收java定义的变量,要把java变量传到session,page,request等对象中
<%pageContext.setAttribute("p", i); %>------把java变量使用pageContext.setAttribute("p", i);加入到page中<br/>
${p}-- el获得java设置的page中的值<br/>
<c:out value="${p }"></c:out> jstl获得java设置的page中的值<br/>
<c:set value="${p }" var="p1"></c:set>
<s:property value="#attr.p"/> ognl使用#attr获得java设置的page中的值<br/>
<s:property value="#attr.p1"/> ognl使用attr获得jstl中的值<br/>
<s:debug></s:debug>
</body>
</html>
struts2 ognl jstl el java代码在jsp页面混用
最新推荐文章于 2024-09-05 11:00:53 发布