Required environment
1. Compiler: JDK
2. Web server: Tomcat
3, Text editor: Sublime, write Java files and JSP files, no words with Notepad also line.
First, establish the structure of the project directory, such as
Can be completed under the operating system, such as the above structure in the D packing directory
Second, in the "Src/com/zyz" directory to establish model class file
Dog.java
Package Com.zyz; Public class Dog { private String name; Public String GetName () { returnthis. Name; } Public void setName (String name) { this. name=name; } }
Third, compile "Dog.java" and output to "Web-inf/classes/com/zyz"
Press "Win+r" to enter "CMD" into the DOS window, enter
D:
CD Shop
Javac src\com\zyz\dog.java-d web-inf\classes
Iv. Create a JSP file under the project root directory, such as "index.jsp"
<%@ Page Language="Java"pageencoding="Utf-8" %><%@ Page Import="Com.zyz.Dog" %><!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"/> <title>Dog Shop</title></Head><Body> <H1> <%Dog D=NewDog (); D.setname ("Huahua"); Out.println (D.getname ()); %> </H1></Body></HTML>
The project is completed and the directory structure is as follows:
Copy the project root "shop" into Tomcat's WebApps directory.
You can delete the SRC directory and post the following directory:
Vi. launch Tomcat and enter "Http://localhost:8080/shop/index.jsp" in the browser
Purely handmade (not using the IDE) Java Web project