javaWeb_JSP

  1. 首先要对项目的pom.xml进行添加依赖
点击查看代码
<dependencies>
    <!--Servlet 依赖-->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
    </dependency>

    <!--JSP 依赖-->
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>javax.servlet.jsp-api</artifactId>
      <version>2.3.3</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!--jstl表达式依赖 -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <!--standard标签库-->
    <!-- https://mvnrepository.com/artifact/taglibs/standard -->
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.2</version>
    </dependency>
  </dependencies>
**2.** <%= 变量或者表达式 %> <%= new java.util.Date() %> <% JSP脚本片段 %> <% int num=0; for (int i=0;i<100;i++){ num+=i; } out.print("

sum="+num+"

"); %> **3.**for 循环
点击查看代码

%>
<%
    for (int i=0;i<5;i++){
%>
<h1>hello</h1>
<%
    }
%>
**4.**JSP声明
点击查看代码
<%!
   static {
       System.out.println("loading Servlet");
   }
   private  int  glo=0;
   private  void print(){
       System.out.println("xixixiix");
   }
%>
**5.**Jsp错误页面跳转 如果遇到 代码错误 好比 1/0 的错误

这块也在web.xml里进行注册代码为

点击查看代码
  <error-page>
    <error-code>500</error-code>
    <location>/img/500.png</location>
  </error-page>
6.将两个页面合成为一个 以下是两种方法 * <%--@include会将两个页面合二为一--%> <%@include file=""%>

hello

<%@include file=""%> *

hello

posted @ 2024-07-24 23:38  梦想_demo  阅读(17)  评论(0)    收藏  举报