JSP

Detailed Explanation of the Use of Expressions in JSP


The JSP expression is used to output information to the page, and its syntax format is as follows:

<%= 表达式 %>

Parameter description:

Expression: It can be a complete expression of any Java speech. The final result of the expression will be converted to a string.

Here are one simple example to demonstrate:

<%@ page language="java" import="java.util.*"
  contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Test JSP Use of expressions </title>
</head>
<body>
  <!--  Output variable  -->
  <%
    String manager = " Xiao Li ";
  %>
   Administrator: <%=manager%>
  <%=" Administrator: " + manager%>
  <!--  Output expression evaluation results  -->
  <%=1 + 2%>
  <!--  Execute Java Code  -->
  <%
    int x = 10;
    out.println(x);
  %>
  <!--  Inserts an expression into the HTML Mark in -->
  <%
    String url = "test.png";
  %>
  <img src="images/<%=url%>" />
  <br>
  <!--  Output system time  -->
  <%=new Date()%>
  <!--  Execute multiple fragments  -->
  <%
    for (int i = 0; i < 5; i++) {
  %>
  <H2>http://blog.csdn.net/u010142437</H2>
  <%
    }
  %>
</body>
</html>