ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# JSP 表达式标签 > 原文: [https://beginnersbook.com/2013/11/jsp-expression-tag/](https://beginnersbook.com/2013/11/jsp-expression-tag/) 表达式标签评估放置在其中的表达式,将结果转换为`String`并通过[`response`对象](https://beginnersbook.com/2013/11/jsp-implicit-object-response-with-examples/ "Response implicit object")将结果发送回客户端。基本上它将结果写入客户端(浏览器)。 **JSP 中表达式标签的语法:** ```html <%= expression %> ``` ## JSP 表达式标签示例 **例 1:值的表达式** 这里我们只是在表达式标签内传递值的表达式。 ```html <html> <head> <title>JSP expression tag example1</title> </head> <body> <%= 2+4*5 %> </body> </html> ``` **输出:** ![expression-tag-example1](https://img.kancloud.cn/b7/b9/b7b9850822abbd67327bb13d1d8c958d_364x145.jpg) **例 2:变量的表达式** 在这个例子中,我们初始化了几个变量,并在表达式标签中传递变量表达式以进行结果评估。 ```html <html> <head> <title>JSP expression tag example2</title> </head> <body> <% int a=10; int b=20; int c=30; %> <%= a+b+c %> </body> </html> ``` **输出:** ![expression-tag-example2](https://img.kancloud.cn/cc/08/cc08411f66ae5a6746e37eecf0ed41a2_364x145.jpg) **示例 3:字符串和隐式对象输出** 在此示例中,我们使用[`application`隐式对象](https://beginnersbook.com/2013/11/jsp-implicit-object-application-with-examples/ "Application object")设置属性,然后使用表达式标签在另一个 JSP 页面上显示该属性和一个简单字符串。 `index.jsp` ```html <html> <head> <title> JSP expression tag example3 </title> </head> <body> <% application.setAttribute("MyName", "Chaitanya"); %> <a href="display.jsp">Click here for display</a> </body> </html> ``` `display.jsp` ```html <html> <head> <title>Display Page</title> </head> <body> <%="This is a String" %><br> <%= application.getAttribute("MyName") %> </body> </html> ``` **输出:** ![expression-tag-output1](https://img.kancloud.cn/57/4d/574d39dca7752c9b63e12d18b08d6280_443x186.jpg) ![expression-tag-output2](https://img.kancloud.cn/60/aa/60aaad370434792b0aaa4ea2e4a12b5d_443x186.jpg)