Home  >  Article  >  Java  >  what is jsp expression

what is jsp expression

(*-*)浩
(*-*)浩Original
2019-05-15 15:38:349909browse

The JSP expression becomes the outprint() method after the page is converted into a Servlet. Therefore, the JSP expression has the same function as the out.print() method embedded in the scriptlet in the JSP page. If an object is output through a JSP expression, the object's toString() method will be automatically called, and the expression will output the content returned by the toString() method.

Recommended course: Java Tutorial.

what is jsp expression

Expression is used to output information on the page. Its usage format is as follows:

<%=变量或可以返回值的方法或 Java 表达式%>

Pay special attention to the "< There should be no space between %" and ".

JSP expressions can be applied to the following situations.

Output content to the page:

<% String name = "www.123.com"; %>
用户名:<%=name%></p>
<p>The above code will generate the following running results: </p>
<pre class="brush:php;toolbar:false">用户名:www.123.com

Generate a dynamic link address :

<% String path = "welcome.jsp"; %>
<a href="<%=path%>">链接到welcome.jsp</a>

The above code will generate the following HTML code:

<a href="welcome.jsp">链接到 welcome.jsp</a>

Dynamicly specify the Form form processing page

<% String name = "logon.jsp"; %>
<form action="<%=name%>"></form>

The above code will generate The following HTML code:

<form action="logon.jsp"></form>

Name the elements generated by the loop statement

<%for(int i=1;i<3;i++) 
{
%>
file<%=i%>:
<input type="text" name="<%="file"+i%>"><br>
<%}%>

The above code will generate the following HTML code:

file1:<input type="text" name="file1"><br>
file2:<input type="text" name="file2"><br>

The above is the detailed content of what is jsp expression. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn