Getting to know JSP
1. Program structure
B/S architecture program (Broswer/server)
Access the application through a browser, such as Taobao browser page
is more convenient to maintain and update the software
usingRequest/responseMode to interact
C/S architecture program (Client/server)
Access the server through the client, such as QQ.
Note: URL-the only naming convention that can identify the location of a specific computer, directory or folder on the Internet, Uniform Resource Locator, which is also a web address, generally consists of a protocol
2. Web server
- It is a program that can provide documents to the requesting browser
- Provide online information browsing service
Tomcat server
Features
- Open source project of Apache Jakarta
- Lightweight application server
- Open source, stable, low resource usage
Configure the environment variable
Tomcat directory to
start Tomcat.
Click the bin directory under the apache-tomcat-8.5.45 file and click startup.bat to start the server. At this time, enter http://localhost:8080 in the web page to access Tomcat Homepage
stop Tomcat
bin\shutdown.bat
Note : localhost is the machine, 8080 is the default port number of Tomcat, you can modify the Tomcat port number through the configuration file server.xml
. Deploy the static website in Tomcat
Copy the project to the webapps folder
三.JSP(Java Server Pages)
1. Concept
-
Java page running on the server
-
Use HTML nested Java code to achieve
2. Working principle
3. Use JSP to achieve output
Note: The syntax is the same as HTML, see the article "Forms" for details
The first
The second
Use out.print to output statements
4. Grammar
-
Use to
<%%>
declare local variables,% is used to write java code -
Use to
<%!%>
declare global variables
-
<%@page%>
Used to set the properties of a JSP page -
<%out.print();%>
Or<%out.println(); %>
realize page output
Comments that JSP can add
- HTML comments:
<!--HTML注释-->
- JSP notes:
<%--JSP注释--%>
- Comment in the JSP script:
<%//单行注释%><%/*多行注释*/%>
5. JSP execution process
6. Summary
- Declare and use variables in JSP. Such as: <%String title="Talking about the spirit of Beijing";%>
- <%=%> Realize page output. Such as: <%=title%>
Common mistakes:
-
<%=title; %>
, Do not write semicolons when using variables -
Use
<%@page%>
guide package. Such as:<%@page import="java.util.Date"%>
-
Output escape characters. Such as:
<%="谈\"北京精神\""%>
Four. Web program debugging and troubleshooting
Common errors in web programs:
404 error-the visited page or resource could not be found
-
URL input error during runtime
-
Put the page under WEB-INF
-
Start Tomcat externally without deploying the project
500 error-wrong JSP page code
- There is an error in the JSP page code
The page cannot be displayed
- Tomcat is not started