是说怎么了,娶不到数据,光棍!!!!
我就随便测试下,结果看下面JSP页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ 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 '11.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>
This is my JSP page. ${path}<br/>${basePath }
<c:out value="${basePath}"></c:out><br/>
<%=basePath %>
<br/>是:${basePath }
</body>
</html>结果页面显示This is my JSP page. http://localhost:8080/shop2/
是:
----------------------
${path}<br/>${basePath }的值没有。。----------------------
何解 以前都好好的
JSP2.0啊
我就随便测试下,结果看下面JSP页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ 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 '11.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>
This is my JSP page. ${path}<br/>${basePath }
<c:out value="${basePath}"></c:out><br/>
<%=basePath %>
<br/>是:${basePath }
</body>
</html>结果页面显示This is my JSP page. http://localhost:8080/shop2/
是:
----------------------
${path}<br/>${basePath }的值没有。。----------------------
何解 以前都好好的
JSP2.0啊
${pageContext.request.queryString} 取得请求的参数字符串
${pageContext.request.requestURL} 取得请求的URL,但不包括请求之参数字符串
${pageContext.request.contextPath} 服务的web application 的名称
${pageContext.request.method} 取得HTTP 的方法(GET、POST)
${pageContext.request.protocol} 取得使用的协议(HTTP/1.1、HTTP/1.0)
${pageContext.request.remoteUser} 取得用户名称
${pageContext.request.remoteAddr } 取得用户的IP 地址
${pageContext.session.new} 判断session 是否为新的
${pageContext.session.id} 取得session 的ID
${pageContext.servletContext.serverInfo} 取得主机端的服务信息
形如:<%@ page isELIgnored="false" %>
改成<%@ taglib uri="http://java.sun.com/jsp/core" prefix="c"%>试试看
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//在这里加一句
request.setAttribute("basePath ")
%>
-----------------------<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param> <!-- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
作用域范转有四个。page范围、request范围、session范围、application范围
还有把<%@ taglib uri="http://java.sun.com/jsp/core" prefix="c"%>这句话放在<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>这句话的下面,不要放在,<% String path....%>的后面
自己做个简单的例子<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<%
List list=new ArrayList();
list.add(1);
list.add(2);
list.add(3);
request.setAttribute("list",list);
%>
<c:forEach items="${list}" var="p">${p}</c:forEach>
</body>
</html>看看能不能打印
你这里把数据放在request作用域里面当然是可以读取的了
我刚才basepath变量是在本地范围的,EL中直接这样取是取不到的,必须在他支持的
四个作用域(pageScope, requestScope, sessionScope和applicationScope)
中取
嗯
就酱紫
谢谢关注
估计就ok了