Developing web project with eclispe

Keywords: Java JSP xml Tomcat

1. After opening eclipse, create a new web project:

new -- dynamic web project

Click Finish to finish the new project!

Adjust font size:

window -- preferences

Select basic,


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>QQ</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Welcome file list represents the welcome page of the project.

2. Introduce Tomcat server

Under eclipse, there is a servers view


If not, go to the window tab and click show view
If you still don't have servers, click other:


Add a server:


Find Tomcat version 7.0:


If you are adding Tomcat for the first time, you need to introduce the following:

Select the web project you want to publish:

3. Create a new welcome page index.jsp in the WebContent directory

Right click webcontent, new, JSP file

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

You can see that the default encoding format of JSP page is ISO-8859-1, which does not support Chinese! So, we need to change it to UTF-8

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

An error message was found:

Because the package needed for web development is still missing, right-click the project, Build Path -- Configure Build Path

Now, let's write a sentence to index.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    
    <h1>Hello web!</h1>
    
</body>
</html>

4. Start up project

Run successfully!

Then, check the port number of the Tomcat:


Port number 8080 found.

4. Visit the welcome page

Open the browser and enter: http://localhost:8080/QQ/

Posted by jack5100nv on Sat, 04 Apr 2020 03:19:53 -0700