1.浏览器?方式传递参数

/**
浏览器地址栏输入?方式传递参数
?test=123
*/
可以用${param.test}方式输出

2.页面内部设置参数setAttribute

/**
JSP页面中输入
<% request.setAttribute("test2", "1234");%>
传递参数
*/
可以在页面代码中输入以下方式输出:
${requestScope.test2}
<%=request.getAttribute("test2") %>

3.servlet设置request参数的访问:

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class TestRequest extends HttpServlet{
void TestRequest(){
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String test2=new String("aaaaa");
request.setAttribute("test2", test2); RequestDispatcher dispatch = request.getRequestDispatcher("/index.jsp"); /*设置跳转页面*/
dispatch.forward(request, response); /*转发request数据到目标页*/
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}

servlet代码

/*JSP代码*/
<body>
This is my JSP page. <br>
${param.test2}
<%=request.getParameter("test2") %>
${requestScope.test2}
<%=request.getAttribute("test2") %>
</body>
/**
访问网址
http://localhost:8080/Test/TestRequest?test2=3333
后运行结果
*/
This is my JSP page.
3333 123456 123456

也就是说

${param.和<%=request.访问url传递的参数

${requestScope.和<%=request.访问的是servlet传递的参数

KEY:

关键 ${requestScope.*},是jsp内置对象,和request.getAttribute相似,都是取得现有的后台的数据

参考:关于EL表达式中requestScope和param区别

JSP参数传递兼EL表达式的更多相关文章

  1. 解决JSP 不解析EL表达式

    解决JSP 不解析EL表达式,jsp在使用EL表达式的时候发现它不被解析,而是直接以字符串的形式显示了出来,经过查阅资料和实践,终于得知了原因并找到了解决方案 原因是:在默认情况下,Servlet 2 ...

  2. jsp页面用el表达式获取枚举的code

    jsp页面用el表达式获取枚举的code <c:set var="D_BUSINESS" value="<%=DeptEnum.D_BUSINESS%> ...

  3. JSP页面用EL表达式 输出date格式

    JSP页面用EL表达式 输出date格式 1.头上引入标签 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix ...

  4. jsp中的el表达式没有解析

    今天发现jsp中的el表达式没有解析,把解决的过程记录一下 在web.xml的web-app节点的版本改成2.4以上

  5. springmvc用model传值到jsp页面,el表达式引用接收不到传递过来的值

    springmvc用model传值到jsp页面,el表达式引用接收不到传递过来的值 查看下controller层代码可以发现,写的是没有错误的. @RequestMapping("list. ...

  6. jsp不解析el表达式,不识别jstl标签,找不到http://java.sun.com/jsp/jstl/core

    问题描述: jsp页面中el表达式,例如:${pageContext.request.contextPath},原样呈现,未被解析. 解决方案: 为jsp页添加page指令如下: <%@ pag ...

  7. jsp页面通过EL表达式获取list大小兼容性处理

    1.jsp页面通过EL表达式获取list大小,中间件用tomcat7时,下面这个写法是可以的 <input id="test" type="hidden" ...

  8. JSP页面使用EL表达式出现的问题:javax.el.PropertyNotFoundException: Property 'ID' not found on type java.lang.Str

    问题描述: 1. 后台返回到JSP前台的的list,在jsp页面使用EL表达式遍历时出现如下问题:javax.el.PropertyNotFoundException: Property 'ID' n ...

  9. JSP标签和EL表达式

    1.jsp标签: sun原生的,直接jsp使用 <jsp:include> -- 实现页面包含,动态包含 <jsp:include page="/index.jsp&quo ...

随机推荐

  1. modem&NIC&sound card

    Rate: Phone:8 k hz   radio:22050 hz Digital Video camcorder; miniDV; DAT LP mode:32 k hz Audio CD MP ...

  2. 99_leetcode_Best Time to Buy and sell Stock

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  3. Write a program that gives count of common characters presented in an array of strings..(or array of

    转自出处 Write a program that gives count of common characters presented in an array of strings..(or arr ...

  4. 【bzoj2282】[Sdoi2011]消防

    两次bfs可得直径,答案一定不会小于所有点到直径的距离最大值,只要把直径上的边权设为0,任选直径上一点bfs可得将最大值作为二分下界,二分直径左右端点的舍弃部分 #include<algorit ...

  5. shell脚本,根据字符串获取行号的

    awk中不能解析shell变量,建议做法是通过-v传递进去: 1 typeline=`cat $typepath | awk -v str="$typetmp" '/str/{pr ...

  6. hive使用

    运行hadoop [root@hadoop0 ~]# start-all.sh 进入命令行[root@hadoop0 ~]# hive 查询昨天的表 hive> select * from st ...

  7. SVN主干与分支的合并 ***

    下面我将step by step地演示如何一次完整的branching和merging,包括创建分支.分支开发.分支和主线同步,分支合并到主线的全过程,甚至包括如何在本地创建一个测试用的reposit ...

  8. Python Flask Web 框架入门

    Python Flask 目录 本文主要借鉴 letiantian 的文章 http://www.letiantian.me/learn-flask/ 一.简介 二.安装 三.初始化Flask 四.获 ...

  9. 【转载】DNS原理及其解析过程

    1.在浏览器中输入www.qq.com域名,操作系统会先检查自己本地的hosts文件是否有这个网址映射关系,如果有,就先调用这个IP地址映射,完成域名解析. 2.如果hosts里没有这个域名的映射,则 ...

  10. System.Drawing.Color的几种使用方法

    System.Drawing.Color   cl   =   Color.Red; System.Drawing.Color   cl   =   Color.FromArgb(255,0,0); ...