<%--输出Java变量或表达式的值--%><%=new java.util.Date()%> <%--&l_arith.round方法">
当前位置:   article > 正文

JSP基础语法_arith.round方法

arith.round方法

JSP的注释不会在客户端显示,HTML会。

EL表达式会自动过滤不存在的值。

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>Title</title>
  5. </head>
  6. <body>
  7. <%--输出Java变量或表达式的值--%>
  8. <%=new java.util.Date()%> <%--<%=%>等价于${}--%>
  9. <%--嵌入Java代码--%>
  10. <%
  11. int sum=0;
  12. for(int i=0;i<100;i++)
  13. sum+=i;
  14. out.print("<h1>"+sum+"<h1>");
  15. %>
  16. <%int x=10;
  17. out.println(x);
  18. %>
  19. <%out.println(x+1);
  20. %>
  21. <%--在代码中嵌入HTML元素--%>
  22. <%
  23. for(int i=0;i<5;i++)
  24. {
  25. %>
  26. <h1>Hello <%=i%></h1>
  27. <%
  28. i++;
  29. }
  30. %>
  31. <%--以上所有的内容都放在_jspService方法中,而下面的内容直接放在类中--%>
  32. <%--JSP声明,可以定义别的方法,也可以定义全局变量--%>
  33. <%!
  34. static
  35. {
  36. System.out.println("Loading");
  37. }
  38. private int glovalVar=0;
  39. public void f()
  40. {
  41. System.out.println("Enter f");
  42. }
  43. %>
  44. </body>
  45. </html>

使用公共头和公共尾:

  1. <html>
  2. <body>
  3. <h2>Hello World!</h2>
  4. <%--web标签,会将三个页面合而为一,这时候如果在不同的页面定义同样的变量就会报错--%>
  5. <%@include file="common/header.jsp"%>
  6. <img src="images/lblue.png" alt="Not Found">
  7. <%
  8. int i=0;
  9. %>
  10. <%@include file="common/footer.jsp"%>
  11. <%--jsp标签,会拼接三个页面,但是本质上还是三个页面--%>
  12. <%--<jsp:include page="/common/header.jsp"/>
  13. <img src="images/login.png"/>
  14. <jsp:include page="common/footer.jsp"/>--%>
  15. </body>
  16. </html>

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
  

闽ICP备14008679号