整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

一步步实现web程序信息管理系统之二-后台框架实现跳转登陆页面

pringBoot

springboot的目的是为了简化spring应用的开发搭建以及开发过程。内部使用了特殊的处理,使得开发人员不需要进行额外繁锁的xml文件配置的编写,其内部包含很多模块的配置只需要添加maven依赖即可使用,这项功能可谓对开发人员提供了大大的好处。使用springboot只需要简单配置一下就可以完成之前复杂的配置过程。可以到https://start.spring.io/此网站上,下载一个最简单的springboot应用,然后一步一步实现自已的应用。

可以看出当前的稳定版本为2.1.0,点击Generate Project 按钮,即可下载一个可用的springboot应用。

这个是我下载下来后,双击后出来的。可以看出以工程是一个基于maven的项目。你可以将其解压到任何一个目录下,通过eclipse或其他IDE进行导入后运行,eclipse导入流程为File->import->maven->existing maven projects,查找到自己的项目目录。也可以基于此工程来建立自已的maven项目。

下面以建立自己的maven项目

建立自己的springboot项目

  • 创建工程

在建立项目时,可以创建一个多模块聚合项目,即在创建项目时选中

选择为pom。

创建后的工程结构为

  • jar包依赖
  • 打开从springboot官网中下载下来的工程目录,打开pom.xml文件
<parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>2.1.0.RELEASE</version>
 <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 <java.version>1.8</java.version>
 </properties>

将此段代码复制到 spring-boot-study工程中的pom文件中

将下面的依赖复制到spring-boot-web工程中的pom文件中

<dependencies>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter</artifactId>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
 </dependency>
 </dependencies>
 <build>
 <plugins>
 <plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 </plugin>
 </plugins>
 </build>

eclipse自动完成项目工程的配置。完成后项目中所有需要依赖的jar包自动配置完成。

  • 代码编写
  • 将application.properties文件拷贝到spring-boot-study项目的resources目录下。文件中的内容暂时先不要管,编写以下代码
@SpringBootApplication
@RestController
public class WebApplication {
 @RequestMapping("/hello")
 public String helloWorld() {
 return "Hello World";
 }
 
 public static void main(String[] args) {
 SpringApplication.run(WebApplication.class, args);
 }
 
}

HelloWold就已经完成后。可以在浏览器中输入localhost:8080/hello即可看到效果

springboot默认启动后的端口为8080,但可以在application.properties文件中进行修改。

server.port=9001

将端口修改为9001,重新启动项目后,在浏览器中输入入localhost:9001/hello同样可以看到相同的结果。

  • 整合login界面
  • 现在后台已经有转发功能,具备web浏览功能。但我们需要访问URL为“/”时跳转到登陆界面,即创建好的登陆界面。本人也是在学习过程中,在网上学习好久才发现使用html的话就使用thymeleaf模板就好了。下面就详细来说说如何使用thymeleaf开发html。
  • 在spring-boot-web项目中的pom文件中加上thymeleaf的依赖。
 <!-- 加入thymeleaf的支持 -->
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-thymeleaf</artifactId>
 </dependency>

但在Spring Boot项目中,一般src/main/resources/static目录用于存放各类静态资源文件,例如css、js和image等。src/main/resources/templates用于存放页面文件,例如html,jsp等。所以在spring-boot-web中的resources目录下创建static目录与templates目录,并将相应的资源文件放置在各自的目录下。

配置thymeleaf

#thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false

html文件修改,增加xmlns:th="http://www.thymeleaf.org" 属性,资源文件的引入要修改。

<link href="../static/css/style.css" th:href="@{/css/style.css}" rel="stylesheet" />
<link href="../static/css/login.css" th:href="@{/css/login.css}" rel="stylesheet" />

然后编写 java代码

@Controller
public class IndexController {
 @RequestMapping("/")
 public String index() {
 return "login";
 }
 
}

重新启动程序,访问localhost:9001/就可成功跳转至login.html登陆界面上。

注:thymeleaf对html标签要求很严格,每一个标签都需要成对出现。

调试过程中遇到下面异常信息

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [login], template might not exist or might not be accessible by any of the configured Template Resolvers
 at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
 at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
 at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
 at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
 at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) [thymeleaf-spring5-。。。。。。。。。。。

因为错将templates写成templatse导致。

至此实现从后端服务访问到登陆界面的搭建,还没有具体登陆逻辑实现。

ervlet 可以与 HTML form 标签一起使用,来允许用户上传文件到服务器。上传的文件可以是文本文件或图像文件或任何文档。

创建一个文件上传表单

下面的 HTML 代码创建了一个文件上传表单。以下几点需要注意:

  • 表单 method 属性应该设置为 POST 方法,不能使用 GET 方法。
  • 表单 enctype 属性应该设置为 multipart/form-data.
  • 表单 action 属性应该设置为在后端服务器上处理文件上传的 Servlet 文件。下面的实例使用了 UploadServlet Servlet 来上传文件。
  • 上传单个文件,您应该使用单个带有属性 type="file" 的 <input .../> 标签。为了允许多个文件上传,请包含多个 name 属性值不同的 input 标签。输入标签具有不同的名称属性的值。浏览器会为每个 input 标签关联一个浏览按钮。
<html>
<head>
<title>文件上传表单</title>
</head>
<body>
<h3>文件上传:</h3>
请选择要上传的文件:<br />
<form action="UploadServlet" method="post" enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="上传文件" />
</form>
</body>
</html>

这将显示下面的结果,允许用户从本地计算机选择一个文件,当用户点击"上传文件"时,表单会连同从本地计算机选择的文件一起提交:

 <b>文件上传:</b> 
请选择要上传的文件:<br /> 
<input type="file" name="file" size="50" /> 
<br /> 
<input type="button" value="上传文件" /> 
<br /> 
注:这只是虚拟的表单,不会正常工作。

编写后台 Servlet

以下是 Servlet UploadServlet,会接受上传的文件,并把它储存在目录 <Tomcat-installation-directory>/webapps/data 中。这个目录名也可以使用外部配置来添加,比如 web.xml 中的 context-param 元素,如下所示:

<web-app>
....
<context-param> 
 <description>Location to store uploaded file</description> 
 <param-name>file-upload</param-name> 
 <param-value>
 c:\apache-tomcat-5.5.29\webapps\data\
 </param-value> 
</context-param>
....
</web-app>

以下是 UploadServlet 的源代码,可以一次处理多个文件的上传。在继续操作之前,请确认下列各项:

  • 下面的实例依赖于 FileUpload,所以一定要确保在您的 classpath 中有最新版本的 commons-fileupload.x.x.jar 文件。可以从 http://commons.apache.org/fileupload/ 下载。
  • FileUpload 依赖于 Commons IO,所以一定要确保在您的 classpath 中有最新版本的 commons-io-x.x.jar 文件。可以从 http://commons.apache.org/io/ 下载。
  • 在测试下面实例时,您上传的文件大小不能大于 maxFileSize,否则文件将无法上传。
  • 请确保已经提前创建好目录 c:\temp and c:\apache-tomcat-5.5.29\webapps\data。
// 导入必需的 java 库
import java.io.*;
import java.util.*;
 
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.output.*;
public class UploadServlet extends HttpServlet {
 
 private boolean isMultipart;
 private String filePath;
 private int maxFileSize = 50 * 1024;
 private int maxMemSize = 4 * 1024;
 private File file ;
 public void init( ){
 // 获取文件将被存储的位置
 filePath = 
 getServletContext().getInitParameter("file-upload"); 
 }
 public void doPost(HttpServletRequest request, 
 HttpServletResponse response)
 throws ServletException, java.io.IOException {
 // 检查我们有一个文件上传请求
 isMultipart = ServletFileUpload.isMultipartContent(request);
 response.setContentType("text/html");
 java.io.PrintWriter out = response.getWriter( );
 if( !isMultipart ){
 out.println("<html>");
 out.println("<head>");
 out.println("<title>Servlet upload</title>"); 
 out.println("</head>");
 out.println("<body>");
 out.println("<p>No file uploaded</p>"); 
 out.println("</body>");
 out.println("</html>");
 return;
 }
 DiskFileItemFactory factory = new DiskFileItemFactory();
 // 文件大小的最大值将被存储在内存中
 factory.setSizeThreshold(maxMemSize);
 // Location to save data that is larger than maxMemSize.
 factory.setRepository(new File("c:\\temp"));
 // 创建一个新的文件上传处理程序
 ServletFileUpload upload = new ServletFileUpload(factory);
 // 允许上传的文件大小的最大值
 upload.setSizeMax( maxFileSize );
 try{ 
 // 解析请求,获取文件项
 List fileItems = upload.parseRequest(request);
 
 // 处理上传的文件项
 Iterator i = fileItems.iterator();
 out.println("<html>");
 out.println("<head>");
 out.println("<title>Servlet upload</title>"); 
 out.println("</head>");
 out.println("<body>");
 while ( i.hasNext () ) 
 {
 FileItem fi = (FileItem)i.next();
 if ( !fi.isFormField () ) 
 {
 // 获取上传文件的参数
 String fieldName = fi.getFieldName();
 String fileName = fi.getName();
 String contentType = fi.getContentType();
 boolean isInMemory = fi.isInMemory();
 long sizeInBytes = fi.getSize();
 // 写入文件
 if( fileName.lastIndexOf("\\") >= 0 ){
 file = new File( filePath + 
 fileName.substring( fileName.lastIndexOf("\\"))) ;
 }else{
 file = new File( filePath + 
 fileName.substring(fileName.lastIndexOf("\\")+1)) ;
 }
 fi.write( file ) ;
 out.println("Uploaded Filename: " + fileName + "<br>");
 }
 }
 out.println("</body>");
 out.println("</html>");
 }catch(Exception ex) {
 System.out.println(ex);
 }
 }
 public void doGet(HttpServletRequest request, 
 HttpServletResponse response)
 throws ServletException, java.io.IOException {
 
 throw new ServletException("GET method used with " +
 getClass( ).getName( )+": POST method required.");
 } 
}

编译和运行 Servlet

编译上面的 Servlet UploadServlet,并在 web.xml 文件中创建所需的条目,如下所示:

<servlet>
 <servlet-name>UploadServlet</servlet-name>
 <servlet-class>UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
 <servlet-name>UploadServlet</servlet-name>
 <url-pattern>/UploadServlet</url-pattern>
</servlet-mapping>

现在尝试使用您在上面创建的 HTML 表单来上传文件。当您在浏览器中访问:http://localhost:8080/UploadFile.htm 时,它会显示下面的结果,这将有助于您从本地计算机上传任何文件。

<b>文件上传:</b> 
请选择要上传的文件:<br /> 
<input type="file" name="file" size="50" /> 
<br /> 
<input type="button" value="上传文件" /> 

如果您的 Servelt 脚本能正常工作,那么您的文件会被上传到 c:\apache-tomcat-5.5.29\webapps\data\ 目录中。

么是JSP

JSP全名为Java Server Pages,java服务器页面。JSP是一种基于文本的程序,其特点就是HTML和Java代码共同存在

为什么需要JSP

JSP是为了简化Servlet的工作出现的替代品,Servlet输出HTML非常困难,JSP就是替代Servlet输出HTML的。

简单使用一下JSP

  • 在idea下生成一个JSP,我们来看一下JSP长什么样子

  • 看起来就像一个HTML页面,前面也说了:JSP的特点就是HTML和Java代码共同存在
  • 我们向浏览器输出一句HelloWorld,至于<%%>这个东西,我先不解释!

JSP的工作原理

  • 在Tomcat博客中我提到过:Tomcat访问任何的资源都是在访问Servlet!,当然了,JSP也不例外!JSP本身就是一种Servlet。为什么我说JSP本身就是一种Servlet呢?其实JSP在第一次被访问的时候会被编译为HttpJspPage类(该类是HttpServlet的一个子类)
  • 刚才我简单使用了一下JSP,它被编译成了这么一个Servlet:

  • 编译过程是这样子的:浏览器第一次请求1.jsp时,Tomcat会将1.jsp转化成1_jsp.java这么一个类,并将该文件编译成class文件。编译完毕后再运行class文件来响应浏览器的请求
  • 以后访问1.jsp就不再重新编译jsp文件了,直接调用class文件来响应浏览器。当然了,如果Tomcat检测到JSP页面改动了的话,会重新编译的
  • 既然JSP是一个Servlet,那JSP页面中的HTML排版标签是怎么样被发送到浏览器的?我们来看下上面1_jsp.java的源码就知道了。原来就是用write()出去的罢了。说到底,JSP就是封装了Servlet的java程序罢了。

  • 有人可能也会问:JSP页面的代码服务器是怎么执行的?再看回1_jsp.java文件,java代码就直接在类中的service()中。
String s = "HelloWorda";
out.println(s);
  • JSP比Servlet更方便更简单的一个重要原因就是:内置了9个对象!内置对象有:out、session、response、request、config、page、application、pageContext、exception,这几个内置对象不在这里讲。现在先知道一下即可!

JSP生命周期

JSP也是Servlet,运行时只有一个实例,JSP初始化和销毁时也会调用Servlet的init()和destroy()方法。另外,JSP还有自己初始化和销毁的方法

JSP的语法

JSP代码可以分为两部分:

  1. 模板数据:就是HTML代码
  2. 元素:JSP页面中的java代码、JSP指令、JSP标签


JSP脚本

  • JSP的脚本就是JSP页面中的java代码,也叫做scriptlet。JSP的脚本必须使用<%%>括起来,不然会被当成是模板数据的!
  • JSP脚本有三种方式:
  • <%%>【定义局部变量,编写语句】
  • <%!%>【定义类或方法,但是没人这样用!
  • <%=%>(也称之为表达式输出)【输出各种类型的变量,int、double、String、Object等】
  • 如果过多地使用<%%>会导致代码混乱,JSP还提供了一种scriptlet标签,使用此标签和<%%>有相同的功能,只不过它更美观了一些
<jsp:scriptlet>
 String s = "HelloWorld";
 out.println(s);
</jsp:scriptlet>

JSP注释

<%--这是JSP注释--%>
<%--%>
//这是java的当行注释
//
/*这是java的多行注释*/
/**/

JSP指令

JSP指令用来声明JSP页面的相关属性,例如编码方式、文档类型等等

JSP指令的语法:

<%@指令 属性名="值" %>


page指令

  • 我在idea生成的JSP页面就有page指令了。
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


  • page指令常见属性:
  • language="java"
  • extends="package.class"
  • import="{package.class | package.*}, …"
  • session="true | false"
  • buffer="none | 8kb | sizekb"
  • autoFlush="true | false"
  • isThreadSafe="true | false"
  • info="text"
  • errorPage="relative_url"
  • isErrorPage="true | false"
  • contentType="mimeType ;charset=characterSet " | "text/html ; charset=ISO-8859-1"
  • pageEncoding="characterSet | ISO-8859-1"
  • isELIgnored="true | false"
  • 一般地,在eclipse或idea这些高级开发工具上开发,我们只需要在page指令中指定contentType="text/html;charset=UTF-8",就不会出现中文乱码问题!
  • 当然了contentType 不仅仅可以指定以text/html的方式显示,还可以使用其他的形式显示出来。在conf/web.xml文件中可以查询出来

  • 比如,我以doc形式显示jsp的数据
<%@ page contentType="application/msword;charset=UTF-8" language="java" %>
<html>
<head>
 <title>简单使用JSP</title>
</head>
<body>
 1111
</body>
</html>
  • 我们上网的时候,如果我们操作不当,或者服务器出错了,页面都是会出现友好提示的!这个也能通过page指令来实现跳转到友好提示页面上
  • page指令errorPage=和isErrorPage这两个属性,下面我们来看一下怎么使用!
  • 1.jsp出现了错误,通过page指令的errorPage属性跳转到error.jsp页面
<%@ page contentType="text/html;charset=UTF-8" language="java" errorPage="error.jsp" %>
<html>
<head>
 <title>该页面出错了!</title>
</head>
<body>
 <%--模拟页面出错了!!!--%>
 <%
 int result = 2 / 0;
 %>
 你好呀
</body>
</html>
  • error.jsp页面要通过page指令的isErrorPage属性设置页面就是错误页面
<%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="true" %>
<html>
 <head>
 <title>友好提示页面</title>
 </head>
 <body>
 服务器正忙着呢!
 </body>
</html>
  • 下面是效果:

  • 当然了,细心的朋友可以发现地址栏是没有变化的,所以属于是服务器跳转。以上的做法是单个页面设置的,如果我会有很多错误(JSP多的情况下,错误就会多),单个设置太麻烦了!
  • 我们可以在web.xml文件中全局设置错误页,只要发生了404错误或者空指针异常的错误都会跳转到error.jsp页面上
<error-page>
 <error-code>404</error-code>
 <location>/error.jsp</location>
</error-page>
<error-page>
 <exception-type>java.lang.NullPointerException</exception-type>
 <location>/error.jsp</location>
</error-page>
  • 随便输个资源进行,会发生发404错误的,跳转到错误页面。下面是效果:


include指令

  • 在讲解request对象的时候,我们曾经使用过request.getRequestDispatcher(String url).include(request,response)来对页头和页尾面进行包含
  • inclue指令也是做这样的事情,我们来试验一下吧!
  • 这是页头
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
 <head>
 <title>页头</title>
 </head>
 <body>
 我是页头
 <br>
 <br>
 <br>
 </body>
</html>
  • 这是页尾
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
 <title>页尾</title>
</head>
<body>
我是页尾
</body>
</html>
  • 在1.jsp中把页头和页尾包含进来
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
 <title>包含页头和页尾进来</title>
</head>
<body>
<%@include file="head.jsp" %>
<%@include file="foot.jsp" %>
</body>
</html>
  • 访问1.jsp

  • include指令是静态包含。静态包含的意思就是:把文件的代码内容都包含进来,再编译!,看一下jsp的源代码就知道了!

  • jsp还提供另一种包含文件的方式:JSP行为---动态包含。jsp行为在下面会讲到!



taglib指令

  • JSP支持标签技术,要使用标签技术就先得声明标签库和标签前缀。taglib指令就是用来指明JSP页面内使用标签库技术。
  • 这里就不详细说明了,等到学习JSP标签的时候再使用吧!现在记住有这个指令即可。



JSP行为

JSP行为(JSP Actions)是一组JSP内置的标签,只书写少量的标记代码就能够使用JSP提供丰富的功能,JSP行为是对常用的JSP功能的抽象和封装

为什么我不把它直接称为JSP标签呢?我把这些JSP内置的标签称之为JSP行为,能够和JSTL标签区分开来。当然了,你也可以把它称之为JSP标签,你不要搞混就行了。我个人喜欢把这些JSP内置标签称之为JSP行为。

include行为

  • 上面已经提及到了,include指令是静态包含,include行为是动态包含其实include行为就是封装了request.getRequestDispatcher(String url).include(request,response)
  • include行为语法是这个样子的
 <jsp:include page=""/>
  • 我们先来使用一下把,在1.jsp页面中也将页头和页尾包含进来
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
 <title>包含页头和页尾进来</title>
</head>
<body>
 <jsp:include page="head.jsp"/>
 <jsp:include page="foot.jsp"/>
</body>
</html>
  • 访问1.jsp页面看一下效果:

  • 使用jsp行为来包含文件,jsp源文件是这样子的:

  • jsp行为包含文件就是先编译被包含的页面,再将页面的结果写入到包含的页面中(1.jsp)
  • 当然了,现在有静态包含和动态包含,使用哪一个更好呢?答案是:动态包含
  • 动态包含可以向被包含的页面传递参数(用处不大),并且是分别处理包含页面的(将被包含页面编译后得出的结果再写进包含页面)【如果有相同名称的参数,使用静态包含就会报错!】
  • 模拟一下场景吧,现在我的头页面有个名为s的字符串变量
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
 <head>
 <title>页头</title>
 </head>
 <body>
 <%
 String s = "zhongfucheng";
 %>
 我是页头呀
 <br>
 <br>
 <br>
 </body>
</html>
  • 我的页尾也有个名为s的字符串变量
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
 <title>页尾</title>
</head>
<body>
<%
 String s = "zhongfucheng";
%>
我是页尾呀
</body>
</html>
  • 现在我使用静态包含看看会发生什么,出现异常了。

  • 出现异常的原因很简单,就是同一个文件中有两个相同的变量s

  • 使用动态包含就可以避免这种情况


param行为

  • 当使用和行为引入或将请求转发给其它资源时,可以使用行为向这个资源传递参数。


forward行为

  • 在讲解request对象的时候,我们使用request.getRequestDispatcher(String url).forward(request,response)进行跳转。其实forward行为就是对其封装
  • 我们来看一下forward的语法:
<jsp:forward page=""/>
  • 好的,我们来使用一下吧。访问1.jsp页面就跳转到head.jsp页面中
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
 <title>访问1.jsp就跳转到head.jsp</title>
</head>
<body>
<jsp:forward page="head.jsp"/>
</body>
</html>
  • 看一下效果

  • 如果我要传递参数,就要在forward行为嵌套param行为
  • 在跳转到head.jsp时传入参数username值为zhongfucheng
<jsp:forward page="head.jsp">
 <jsp:param name="username" value="zhongfucheng"/>
</jsp:forward>
  • 在head.jsp页面中获取到传递过来的参数
<%
 String ss = request.getParameter("username");
%>
获取到的参数是:
<%=ss%>
  • 效果如下图所示

directive行为

  • directive的中文意思就是指令该行为就是替代指令<%@%>的语法的
  • 相当于<%@include file="" %>
  • 相当于<%@page %>
  • 相当于<%@taglib %>
  • 我们来试一下能不能用的
<jsp:directive.include file="head.jsp"></jsp:directive.include>
<jsp:directive.include file="foot.jsp"></jsp:directive.include>
  • 看下效果,正常可以包含页面:

  • 使用该指令可以让JSP页面更加美观
  • 使用scriptlet行为替代<%%>是同样一个道理


javaBean行为

  • JSP还提供了操作javaBean对象的行为在这里就不详细说明了,后面会讲到的!现在记住JSP提供了javaBean行为来操作简单类即可!
<jsp:useBean id=""/>
<jsp:setProperty name="" property=""/>
<jsp:getProperty name="" property=""/>

文章来源:https://dwz.cn/OtXvyvh3

作者:Java3y