Guide to JavaServer Pages (JSP) – Java服务器页面(JSP)指南

最后修改: 2016年 12月 1日

Table of Contents

目录

1. Overview

1.概述

JavaServer Pages (JSP) allows dynamic content injection into static contents using Java and Java Servlets. We can make requests to a Java Servlet, perform relevant logic, and render a specific view server-side to be consumed client-side. This article will provide a thorough overview of JavaServer Pages using Java 8 and Jave 7 EE.

JavaServer Pages(JSP)允许使用Java和Java Servlet将动态内容注入静态内容。我们可以向Java Servlet发出请求,执行相关的逻辑,并在服务器端渲染一个特定的视图,以便在客户端消费。本文将对使用Java 8和Jave 7 EE的JavaServer Pages进行全面介绍。

We’ll start by exploring a few key concepts relevant to JSP: namely, the difference between dynamic and static contents, the JSP lifecycle, and JSP syntax as well as directives and the implicit objects created at compilation!

我们将首先探讨与JSP有关的几个关键概念:即动态静态内容之间的区别、JSP生命周期、JSP语法以及指令和编译时创建的隐含对象!

2. JavaServer Pages

2.JavaServer Pages

JavaServer Pages (JSP) enabled Java-specific data to be passed into or placed within a .jsp view and consumed client-side.

JavaServer Pages (JSP)使Java特定的数据能够被传入或放置在.jsp视图中,并在客户端被消耗。

JSP files are essentially .html files with some extra syntax, and a couple of minor initial differences:

JSP文件本质上是.html文件,有一些额外的语法,以及一些微小的初始差异。

  1. the .html suffix is replaced with .jsp (it’s considered a .jsp filetype) and
  2. the following tag is added to the top of the .html markup elements:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

Let’s go over some of the key concepts in JSP.

让我们回顾一下JSP中的一些关键概念。

2.1. JSP Syntax

2.1.JSP语法

There are two ways to add Java code to a .jsp. First, we can use basic Java Scriptlet syntax which involves placing Java code blocks within two Scriptlet tags:

有两种方法可以在.jsp中添加Java代码。首先,我们可以使用基本的Java Scriptlet语法,即把Java代码块放在两个Scriptlet标签中。

<% Java code here %>

The second method is specific to XML:

第二种方法是专门针对XML的。

<jsp:scriptlet>
    Java code here
</jsp:scriptlet>

Importantly, one can use conditional logic clientside with JSP by using if, then, and else clauses and then wrapping the relevant blocks of markup with those brackets.

重要的是,通过使用ifthenelse子句,然后用这些括号包装相关的标记块,我们可以在客户端使用JSP的条件逻辑。

<% if (doodad) {%>
    <div>Doodad!</div>
<% } else { %>
    <p>Hello!</p>
<% } %>

For example, if doodad is true, we would display the first, div element otherwise we would display the second, p element!

例如,如果doodad为真,我们将显示第一个,div元素,否则我们将显示第二个,p元素!

2.2. Static and Dynamic Contents

2.2.静态动态内容

Static web contents are fixed assets that are consumed independently of RESTful, SOAP, HTTP, HTTPS requests, or other user-submitted information.

静态网络内容是独立于RESTful、SOAP、HTTP、HTTPS请求或其他用户提交的信息而被消费的固定资产。

Static content, however, is fixed and is not modified by user inputs. Dynamic web contents are those assets that respond to, are modified by, or change in light of user actions or information!

然而,静态内容是固定的,不被用户输入修改。动态网络内容是那些对用户行动或信息做出反应、被其修改或改变的资产

JSP technology allows for the clean separation of responsibilities between dynamic and static contents.

JSP技术允许在动态静态内容之间进行明确的责任分离。

The server (servlet) manages the dynamic contents and the client (the actual .jsp page) is the static context into which dynamic contents are injected.

服务器(servlet)管理动态内容,客户端(实际的.jsp页面)是静态环境,动态内容被注入其中。

Let’s take a look at the implicit objects that are created by JSP and which allow you to access JSP-relevant data server-side!

让我们来看看由JSP创建的隐式对象,它允许你在服务器端访问JSP相关的数据!

2.3. Implicit Objects

2.3.隐式对象

Implicit objects are generated by the JSP engine automatically during compilation.

隐式对象是由JSP引擎在编译时自动生成的。

Implicit objects include the HttpRequest and HttpResponse objects and expose various serverside functionalities for use in your servlet and for interacting with your .jsp! Here’s the list of implicit objects that are created:

隐式对象包括HttpRequestHttpResponse对象,并暴露了各种服务器端的功能,用于你的servlet和与你的.jsp交互!下面是创建的隐式对象的列表。

request
request belongs to the class javax.servlet.http.HttpServletRequest. The request object exposes all user inputs data and makes it available serverside.

request
request属于javax.servlet.http.HttpServletRequest类。request对象暴露了所有的用户输入数据并使其在服务器端可用。

response
response belongs to the class javax.servlet.http.HttpServletResponse and determines what is passed back clientside after a request is made.

response
response属于javax.servlet.http.HttpServletResponse类,它决定了在发出request后,客户端会传回什么。

Let’s take a closer look at the request and response implicit objects since they’re the most important and heavily-used ones.

让我们仔细看看requestresponse隐式对象,因为它们是最重要和最常用的对象。

The example below demonstrates a very simple, incomplete, servlet method to handle GET requests. I’ve omitted most of the details so that we can focus on how to use the request and response objects:

下面的例子演示了一个非常简单的、不完整的、处理GET请求的Servlet方法。我省略了大部分细节,这样我们就可以把注意力放在如何使用requestresponse对象上。

protected void doGet(HttpServletRequest request, 
  HttpServletResponse response) throws ServletException, IOException {
    String message = request.getParameter("message");
    response.setContentType("text/html");
    . . .
}

First, we see that the request and response objects are passed in as parameters into the method making them available within its scope.

首先,我们看到requestresponse对象被作为参数传入方法中,使它们在其范围内可用。

We can access request parameters using the .getParameter() function. Above, we snag the message parameter and initialize a string variable so we can use it in our server-side logic. We can also access the response object which determines what and how the data passed into the view will be.

我们可以使用.getParameter()函数访问请求参数。上面,我们抓取了message参数并初始化了一个字符串变量,这样我们就可以在服务器端逻辑中使用它。我们还可以访问response对象,它决定了传递到视图中的数据是什么以及如何传递。

Above we set the content type on it. We don’t need to return the response object to have it’s payload display on the JSP page at render!

上面我们对它设置了内容类型。我们不需要返回response对象来让它的有效载荷在渲染时显示在JSP页面上!

out
out belongs to the class javax.servlet.jsp.JspWriter and is used to write content to the client.

out
out属于javax.servlet.jsp.JspWriter类,用于向客户端写入内容。

There are at least two ways to print to your JSP page and its worth discussing both here. out is created automatically and allows you to write to memory and then to the response object:

至少有两种方法可以打印到你的JSP页面,这里值得讨论一下。out是自动创建的,它允许你写到内存,然后写到response对象。

out.print(“hello”);
out.println(“world”);

That’s it!

就这样吧!

The second approach can be more performant since it allows you to write directly to the response object! Here, we use PrintWriter:

第二种方法可能更有性能,因为它允许你直接向response对象写东西!这里,我们使用PrintWriter

PrintWriter out = response.getWriter();
out.println("Hello World");

2.4. Other Implicit Objects

2.4.其他隐式对象

Here are some other Implicit objects that are also good to know!

这里有一些其他的隐性对象,也是很好了解的!

session
session belongs to the class javax.servlet.http.HttpSession maintains user data for the duration of the session.

session
session属于javax.servlet.http.HttpSession类,在会话期间保持用户数据。

application
application belongs to the class javax.servlet.ServletContext stores application-wide parameters set at initialization or that need to be accessed application-wide.

application
application属于javax.servlet.ServletContext类,用于存储初始化时设置的或需要在整个应用中访问的应用范围的参数。

exception
exception belongs to the class javax.servlet.jsp.JspException is used to display error messages on JSP pages which have the tag <%@ page isErrorPage=”true” %>.

exception
exception属于javax.servlet.jsp.JspException类,用于在有<%@ page isErrorPage=”true” %>标签的JSP页面上显示错误信息。

page
page belongs to the class java.lang.Object allows one to access or reference current servlet information.

page
page属于java.lang.Object类,允许人们访问或引用当前的Servlet信息。

pageContext
pageContext belongs to the class javax.servlet.jsp.PageContext defaults to page scope but can be used for accessing request, application, and session attributes.

pageContext
pageContext属于javax.servlet.jsp.PageContext类,默认为page范围,但可用于访问requestapplication以及session属性

config
config belongs to the class javax.servlet.ServletConfig is the servlet configuration object allowing one to get the servlet context, name, and configuration parameters.

config
config属于javax.servlet.ServletConfig类,是Servlet配置对象,允许人们获得Servlet上下文、名称和配置参数。

Now that we’ve covered the implicit objects provided by JSP, let’s turn to directives which allow .jsp pages to (indirectly) access some of these objects.

现在我们已经介绍了JSP提供的隐式对象,让我们来看看指令,它允许.jsp页面(间接地)访问这些对象中的一些。

2.5. Directives

2.5.指令

JSP supplies out of the box directives that can be used to specify core functionalities for our JSP files. There are two parts to JSP directives: (1) the directive itself and (2) the attribute of that directive which is assigned a value.

JSP提供了开箱即用的指令,可以用来为我们的JSP文件指定核心功能。JSP指令有两个部分:(1)指令本身和(2)该指令的属性,该属性被赋予一个值。

The three kinds of directives that can be referenced using directive tags are <%@ page … %> which defines dependencies and attributes of the JSP including content type and language, <%@ include … %> which specifies an import or file to be used, and <%@ taglib …%> which specifies a tag library defining custom actions to be used by a page.

可以使用指令标签引用的三种指令是:<%@ page … %>,它定义了JSP的依赖性和属性,包括内容类型语言<%@ include …%>,它指定了要使用的导入或文件,以及<%@ taglib …%>,它指定了一个标签库,定义了要被页面使用的自定义动作。

So, as an example, a page directive would be specified using JSP tags in the following way: <%@ page attribute=”value” %>

因此,作为一个例子,一个页面指令将用JSP标签以如下方式指定。<%@ page attribute=”value” %>

And, we can do that using XML as follows: <jsp:directive.page attribute=”value” />

而且,我们可以使用XML来实现,如下所示。<jsp:directive.page attribute=”value” />

2.6. Page Directive Attributes

2.6.页面指令属性

There are a lot of attributes that can be declared within a page directive:

有很多属性可以在一个页面指令中声明。

autoFlush <%@ page autoFlush=”false” %>

自动冲洗<%@ page autoFlush=”false” %>/em>

autoFlush controls the buffer output, clearing it out when the buffer size is reached. The default value is true.

autoFlush控制缓冲区的输出,在达到缓冲区大小时将其清除。默认值是true

buffer <%@ page buffer=”19kb” %>

buffer <%@ page buffer=”19kb” %>

buffer sets the size of the buffer used by our JSP page. The default value is 8kb.

buffer设置我们的JSP页面所使用的缓冲区的大小。默认值是8kb。

errorPage <%@ page errorPage=”errHandler.jsp” %>

errorPage <%@ page errorPage=”errHandler.jsp” %>

errorPage specifies a JSP page as an error page.

errorPage指定一个JSP页面作为错误页面。

extends <%@ page extends=”org.apache.jasper.runtime.HttpJspBase” %>

extends <%@ page extends=”org.apache.jasper.runtime.HttpJspBase” %>

extends specifies the super class of the corresponding servlet code.

extends指定了相应servlet代码的超级类。

info <%@ page info=”This is my JSP!” %>

info <%@ page info=”这是我的JSP!”%>

info is used to set a text-based description for the JSP.

info是用来为JSP设置一个基于文本的描述。

isELIgnored <%@ page isELIgnored=”true” %>

isELIgnored <%@ page isELIgnored=”true” %>/em>

isELIgnored states whether or not the page will ignore Expression Language (EL) in JSP. EL enables the presentation layer to communicate with Java managed beans and does so using ${…} syntax and while we won’t get into the nitty-gritties of EL here, there are several examples found below that are sufficient to build our example JSP app! The default value for isELIgnored is false.

isELIgnored说明页面是否会忽略JSP中的Expression Language(EL)。EL使表现层能够与Java管理豆进行通信,并使用${…}语法,虽然我们不会在这里讨论EL的细枝末节,但下面有几个例子足以建立我们的JSP应用实例isELIgnored的默认值是false

isErrorPage <%@ page isErrorPage=”true” %>

isErrorPage <%@ page isErrorPage=”true” %>/em>

isErrorPage says whether or not a page is an error page. We must specify an error page if we create an error handler for our page within the application.

isErrorPage表示一个页面是否是一个错误页面。如果我们在应用程序中为我们的页面创建一个错误处理程序,我们必须指定一个错误页面。

isThreadSafe <%@ page isThreadSafe=”false” %>

isThreadSafe <%@ page isThreadSafe=”false” %>/em>

isThreadSafe has a default value of true. isThreadSafe determines whether or not the JSP can use Servlet multi-threading. In general, you would never want
to turn off that functionality.

isThreadSafe的默认值为trueisThreadSafe决定了JSP是否可以使用Servlet多线程。一般来说,你永远不会想
关掉这个功能。

language <%@ page language=”java” %>

language <%@ page language=”java” %>

language determines what scripting language to use in the JSP. The default value is Java.

language决定了在JSP中使用什么脚本语言。默认值是Java

session <%@ page session=”value”%>

session <%@ page session=”value”%>

session determines whether or not to maintain the HTTP session. It defaults to true and accepts values of true or false.

session决定是否维护HTTP会话。它的默认值是true,接受truefalse

trimDirectiveWhitespaces <%@ page trimDirectiveWhitespaces =”true” %>

trimDirectiveWhitespaces <%@ page trimDirectiveWhitespaces =”true” %>

trimDirectiveWhitespaces stripes out white-spaces in the JSP page condensing the code into a more compact block at compile-time. Setting this value to true may help to reduce the size of the JSP code. The default value is false.

trimDirectiveWhitespaces将JSP页面中的白色空间剥离出来,在编译时将代码压缩成一个更紧凑的块。将此值设置为true可能有助于减少JSP代码的大小。默认值是false

3. Three Examples

3.三个例子

Now that we’ve reviewed the concepts central to JSP, let’s apply those concepts to some basic examples that will help you to get your first JSP-serving servlet up and running!

现在我们已经回顾了JSP的核心概念,让我们把这些概念应用到一些基本的例子中去,这将有助于你建立和运行你的第一个JSP服务的servlet!

There are three main ways to inject Java into a .jsp and we’ll explore each of those ways below using native functionalities in Java 8 and Jakarta EE.

在.jsp中注入Java有三种主要方式,下面我们将利用Java 8和Jakarta EE中的原生功能来探讨每一种方式。

First, we’ll render our markup server-side to be displayed client-side. Second, we’ll look at how to add Java code directly into our .jsp file independent of javax.servlet.http‘s request and response objects.

首先,我们将在服务器端渲染我们的标记以显示在客户端。其次,我们将研究如何在独立于javax.servlet.httprequestresponse对象的.jsp文件中直接添加Java代码。

Third, we’ll demonstrate how to both forward an HttpServletRequest to a specific .jsp and bind server-side processed Java to it.

第三,我们将演示如何将一个HttpServletRequest转发到一个特定的.jsp,并将服务器端处理的Java绑定到它。

Let’s set up our project in Eclipse using the File/New/Project/Web/Dynamic web project/ type to be hosted in Tomcat! You should see after creating the project:

让我们在Eclipse中使用File/New/Project/Web/Dynamic web project/类型来设置我们的项目,以便在Tomcat中托管!创建项目后,你应该看到。

|-project
  |- WebContent
    |- META-INF
      |- MANIFEST.MF
    |- WEB-INF
      |- lib
      |- src

We’re going to add a few files to the application structure so that we end up with:

我们要在应用程序结构中添加一些文件,这样我们最终会有。

|-project
  |- WebContent
    |- META-INF
      |- MANIFEST.MF
    |- WEB-INF
      |-lib
      *-web.xml
        |- ExampleTree.jsp
        |- ExampleTwo.jsp
        *- index.jsp
      |- src
        |- com
          |- baeldung
            *- ExampleOne.java
            *- ExampleThree.java

Let’s set up index.jsp which will be displayed when we access the URL context in Tomcat 8:

让我们来设置index.jsp,当我们在Tomcat 8中访问URL上下文时将会显示。

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>JSP Examples</title>
    </head>
    <body>
        <h1>Simple JSP Examples</h1>
        <p>Invoke HTML rendered by Servlet: <a href="ExampleOne" target="_blank">here</a></p>
        <p>Java in static page: <a href="ExampleTwo.jsp" target="_blank">here</a></p>
        <p>Java injected by Servlet: <a href="ExampleThree?message=hello!" target="_blank">here</a></p>
    </body>
</html>

There are three a, each linking to one of the examples we’ll go through below in sections 4.1 through 4.4.

有三个a,每个都链接到我们在下面4.1到4.4节中要讨论的一个例子。

We also need to make sure that we’ve got our web.xml set up:

我们还需要确保我们已经把web.xml设置好。

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>ExampleOne</servlet-name>
    <servlet-class>com.baeldung.ExampleOne</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ExampleOne</servlet-name>
    <url-pattern>/ExampleOne</url-pattern>
</servlet-mapping>

A main note here is – how to correctly map each of our servlets to a particular servlet-mapping.Doing so associates each servlet with a specific endpoint where it can consumed! Now, we’ll go through each of the other files below!

这里的一个主要注意事项是–如何正确地将我们的每个servlet映射到一个特定的servlet-mapping.这样做可以将每个servlet与一个特定的端点联系起来,在那里它可以被消费现在,我们再来看看下面的其他文件!

3.1. HTML Rendered in Servlet

3.1.在Servlet中进行HTML渲染

In this example, we’ll actually skip building a .jsp file!

在这个例子中,我们实际上将跳过建立一个.jsp文件!

Instead, we’ll create a string representation of our markup and then write it to the GET response with PrintWriter after ExampleOne Servlet receives a GET request:

相反,我们将为我们的标记创建一个字符串表示,然后在ExampleOne Servlet收到GET请求后用PrintWriter将其写入GET响应。

public class ExampleOne extends HttpServlet {
  @Override
  protected void doGet(HttpServletRequest request, 
    HttpServletResponse response) throws ServletException, IOException {
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println(
	"<!DOCTYPE html><html>" +
	"<head>" +
	"<meta charset=\"UTF-8\" />" +
	"<title>HTML Rendered by Servlet</title>" +
	"</head>" +
	"<body>" +
	"<h1>HTML Rendered by Servlet</h1></br>" +
	"<p>This page was rendered by the ExampleOne Servlet!</p>" +
	"</body>" +
	"</html>"
     );
   }
}

What we’re doing here is injecting our markup through our servlet request handling directly. Instead of a JSP tag, we generate our HTML, along with any and all Java-specific data to be inserted, purely server-side without a static JSP!

我们在这里所做的是通过我们的Servlet请求处理直接注入我们的标记。而不是一个JSP标签,我们生成我们的HTML,以及任何和所有要插入的Java特定数据,纯粹是服务器端,没有一个静态的JSP!

Earlier, we reviewed the out object which is a feature of JspWriter.

早些时候,我们审查了out对象,它是JspWriter的一个特征。

Above, I used the PrintWriter object instead which writes directly to the response object.

上面,我使用了PrintWriter对象,它直接写到response对象。

JspWriter actually buffers the string to be written into memory which is then written to the response objects after the in-memory buffer is flushed.

JspWriter实际上缓冲了要写入内存的字符串,然后在内存缓冲区被刷新后被写入response对象。

PrintWriter is already attached to the response object. I’ve preferred to write directly to the response object in the examples above and below for those reasons.

PrintWriter已经附着在response对象上。由于这些原因,在上面和下面的例子中,我倾向于直接写到response对象。

3.2. Java in a JSP Static Content

3.2.JSP静态内容中的Java

Here we create a JSP file named ExampleTwo.jsp with a JSP tag. As seen above, this allows Java to be added directly into our markup. Here, we randomly print an element of a String[]:

在这里,我们创建了一个名为ExampleTwo.jsp的JSP文件,其中有一个JSP标签。如上所述,这允许将Java直接添加到我们的标记中。在这里,我们随机打印一个String[]的元素。

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
    <head>
        <title>Java in Static Page Example</title>
    </head>
    <body>
        <h1>Java in Static Page Example</h1>
	    <% 
              String[] arr = {"What's up?", "Hello", "It's a nice day today!"}; 
	      String greetings = arr[(int)(Math.random() * arr.length)];	
            %>
        <p><%= greetings %></p>
    </body>
</html>

Above, you’ll see that variable declaration within JSP tags objects: type variableName and an initialization just like regular Java.

上面,你会看到JSP标签内的变量声明对象。type variableNameinitialization就像普通Java一样。

I’ve included the above example to demonstrate how to add Java to a static page without making recourse to a specific servlet. Here, Java is simply added to a page and the JSP lifecycle takes care of the rest.

我在上面的例子中展示了如何将Java添加到一个静态页面中,而不用求助于特定的Servlet。在这里,Java被简单地添加到一个页面中,而JSP的生命周期则负责其余的工作。

3.3. JSP With Forwarding

3.3.带有转发功能的JSP</strong

Now, for our final and most involved example! Here, we’re going to use the @WebServlet annotation on ExampleThree which eliminates the need for servlet mappings in server.xml.

现在,我们来看看最后一个也是涉及最多的例子!在这里,我们将在ExampleThree上使用@WebServlet注解,这样就不需要在server.xml中进行Servlet映射了。

@WebServlet(
  name = "ExampleThree",
  description = "JSP Servlet With Annotations",
  urlPatterns = {"/ExampleThree"}
)
public class ExampleThree extends HttpServlet {
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response) 
    throws ServletException, IOException {
      String message = request.getParameter("message");
      request.setAttribute("text", message);
      request.getRequestDispatcher("/ExampleThree.jsp").forward(request, response);
   }
}

ExampleThree takes a URL parameter passed in as message, binds that parameter to the request object, and then redirects that request object to ExampleThree.jsp.

ExampleThree接收一个作为message传递的URL参数,将该参数绑定到request对象,然后将该request对象重定向到ExampleThree.jsp

Thus, we’ve not only accomplished a truly dynamic web experience but we’ve also done so within an application containing multiple .jsp files.

因此,我们不仅实现了真正的动态网络体验,而且还在一个包含多个.jsp文件的应用程序中实现了这一点。

getRequestDispatcher().forward() is a simple way to ensure that the correct .jsp page is rendered.

getRequestDispatcher().forward()是一个简单的方法来确保正确的.jsp页面被呈现。

All the data bound to the request object sent its (the .jsp file’s) way will then be displayed! Here’s how we handle that last part:

所有与request对象绑定的数据以其(.jsp文件)的方式发送,然后将被显示出来下面是我们处理最后一部分的方法。

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
    <head>
        <title>Java Binding Example</title>
    </head>
    <body>
        <h1>Bound Value</h1>
	    <p>You said: ${text}</p>
    </body>
</html>

Note the JSP tag added to the top of ExampleThree.jsp. You’ll notice that I switched the JSP tags here. I’m using Expression Language (which I mentioned before) to render our set parameter (which is bound as ${text})!

注意在ExampleThree.jsp的顶部添加的JSP标签。你会注意到,我在这里调换了JSP标签。我使用表达式语言(我之前提到过)来渲染我们的设定参数(它被绑定为${text})!

3.4. Try It Out!

3.4.试试吧!

Now, we’ll export our application into a .war to be launched and hosted in Tomcat 8! Find your server.xml and we’ll update our Context to:

现在,我们将把我们的应用程序导出为一个.war,以便在Tomcat 8中启动和托管找到你的server.xml,我们将更新我们的Context到。

<Context path="/spring-mvc-xml" docBase="${catalina.home}/webapps/spring-mvc-xml">
</Context>

Which will allow us to access our servlets and JSP’s on localhost:8080/spring-mvc-xml/jsp/index.jsp! Pick up a working copy over at: GitHub. Congrats!

这将允许我们在localhost:8080/spring-mvc-xml/jsp/index.jsp上访问我们的Servlet和JSP!领取一份工作副本,请点击。GitHub。祝贺你!

4. Conclusion

4.结论

We’ve covered quite a bit of ground! We’ve learned about what JavaServer Pages are, what they were introduced to accomplish, their lifecycle, how to create them, and finally a few different ways to implement them!

我们已经覆盖了相当多的领域!我们已经了解了什么是Java服务器页面,它们被引入的目的是什么,它们的生命周期,如何创建它们,最后还有一些实现它们的不同方法

This concludes the introduction to JSP! Be well and code on!

对JSP的介绍到此结束!祝你健康,并继续编码!