tomcat执行JSP依赖及相关资料

【maven依赖】
//tomcat8.5.x依赖 
<dependencies>
<!-- 添加Servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- 添加JSP API -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<!-- 添加JSTL API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>


【核心代码】
  req.setAttribute("showstu", showstu);
        req.getRequestDispatcher("showStu.jsp").forward(req,resp);    
 <c:forEach items="${requestScope.showstu}" var="data1">
                <tr>
                    <td>${data1.sid}</td>
                    <td>${data1.sname}</td>
                    <td>${data1.sage}</td>
                    <td>${data1.ssex}</td>
                    <td>${data1.sbirthday}</td>
                </tr>
            </c:forEach>
<%@ taglib uri="Oracle Java Technologies | Oracle" prefix="c" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>

【Tomcat10依赖】
  <dependencies>
    <dependency>
      <groupId>jakarta.servlet</groupId>
      <artifactId>jakarta.servlet-api</artifactId>
      <version>5.0.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>jakarta.servlet.jsp</groupId>
      <artifactId>jakarta.servlet.jsp-api</artifactId>
      <version>3.0.0</version>
      <scope>provided</scope>
    </dependency>
    <!--    mysql依赖-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.27</version>
    </dependency>
    <!-- 添加JUnit依赖 -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
    </dependency>
    <!--JSTL表达式的依赖 -->
    <dependency>
      <groupId>jakarta.servlet.jsp.jstl</groupId>
      <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
      <version>2.0.0</version>
      <scope>provided</scope>
    </dependency>
    <!-- standard标签库 -->
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.2</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp.jstl</groupId>
      <artifactId>jstl-api</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.taglibs</groupId>
      <artifactId>taglibs-standard-impl</artifactId>
      <version>1.2.5</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.taglibs</groupId>
      <artifactId>taglibs-standard-spec</artifactId>
      <version>1.2.5</version>
      <scope>runtime</scope>
    </dependency>

【资料】
//(资料1:jstl(c标签)及jstl.jar区别
out是JSP九大内置对象之一,是JspWriter的一个对象,JspWriter继承了java.io.Writer类。
out.print()和out.write()
print()和println()是JspWriter类中定义的方法,write()则是Writer类中定义的。
print()和println()方法可将各种类型的数据转换成字符串的形式输出,
而write()方法只能输出字符、字符数组和字符串等与字符相关的数据。
如果字符串对象的值为null,print()和println()方法将输出内容为“null”的字符串,而write()方法则是抛出NullPointerException异常。
out.print()和out.println()
println()虽然看似是换行,但转成网页之后,这种换行被认为是空格,所以输出的仍然是一行,用空格分隔,但右键点击页面查看源代码时,能看出换行起作用了。
所以在页面上需要换行的话,需要用<br/>。
//(资料3:JSP中转发和重定向的区别
1.请求转发
1> 服务器发起的请求
2> 一次请求
3> 浏览器地址没有发生改变
4> request作用域有效
eg: <%request.getRequestDispatcher("/目标.jsp").forward(request,response);%>
注意:转发是服务器内部自己转发,例如A发起请求到B,B转发到C,地址栏的地址不会改变还是B的地址,request作用域在C页面有效,还可以访问到。
2.请求重定向
1> 客户端发起的请求
2> 两次请求
3> 浏览器地址发生改变
4> request作用域失效
eg: <%response.sendRedirect(request.getContextPath()+"/目标.jsp");%>
注意:请求重定向是客户端发起的请求,例如A发起请求到B,B获得请求后反馈给A重定向的地址和重定向的参数,A收到之后按照地址重定向到C,但是实际地址发生改变成为了C的地址,request作用域在C页面失效。
【Tomcat版本下载】
链接:  百度网盘 请输入提取码
提取码: 7890 
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值