Difference between jsp expression tags <% and <%=

前端 未结 2 1120
我寻月下人不归
我寻月下人不归 2021-02-04 08:47

I more or less know the difference between <%! and <%, but I can\'t seem to find the difference between <%= and <%. I\'m trying to avoid a null value error by intr

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 09:23

    Between <%...%>you can write any logic that you want in java.

    Using <%=...%> will output the result of the expression between the brackets to the screen. So instead of writing for example

    <% System.out.println("Hello World") %> 
    

    you can simply write

    <%= "Hello world" %> 
    

    Basically, what <%= %> does is to call the toString() method of the expression that is being evaluated.

    If you need to add null check logic as you said you need you can use

     <%..%>
    

    Here's a link you can refer to:

    http://www.easywayserver.com/jsp/JSP-example.htm http://www.tutorialspoint.com/jsp/jsp_syntax.htm

提交回复
热议问题