Introduction to 1.java Web
1.1 Static pages and dynamic pages
|
form of expression |
The required technology |
Static Web page |
Web page content fixed, not updated |
Html,css |
Dynamic Web pages |
Web content is dynamically displayed by the program and updated automatically |
Html,css,db,java/c#/php,javascript,xml, the mainstream Dynamic Web script (jsp,asp.net,php) |
1.2 Building a Java Web development environment
Jdk1.7+tomcat7.0+myeclipse10. See http://blog.sina.com.cn/s/blog_907043b301016jtp.html for installation and configuration of the myeclipse. The Tomcat server is an open source project for Apache Jakarta and is a Jsp/servlet container. Installing Tomcat only requires unpacking the ZIP package to the specified directory. Create a new environment variable catalina_home, and the value of the variable is the root directory of Tomcat D:\Program Files (x86) \apache-tomcat-7.0.57. The entire environment variable is as follows:
Variable name |
Variable Value |
Java_home |
D:\Program Files (x86) \java\jdk1.7.0_40 |
Path |
C:\Program Files\Microsoft SQL Server\100\dts\binn\;%java_home%\bin;d:\program Files\sublime Text 3;D:\Program Files\ Mysql\mysql Utilities 1.3.6\ |
Classpath |
.; %java_home%\lib\rt.jar;%java_home%\lib\tools.jar; |
Catalina_home |
D:\Program Files (x86) \apache-tomcat-7.0.57 |
Then we test Tomcat's homepage:
Enter the bin directory below the root of the Tomcat server and run Startup.bat as an administrator, indicating that the Tomcat server started successfully if the result is as follows.
Note: do not close this window (close the window means to close the Tomcat server and minimize it).
Enter http://localhost:8080/return in the browser address bar to get the following page:
1.3TOMCAT directory Structure
1.4 Writing the first Web application manually
Create a index.jsp in the project folder:
1 <! DOCTYPE html> 2 3 4 <meta charset= "UTF-8" > 5 <title> hand-written first Java Web project </title> 6 7 <body> 8 9 </body>11
Create a copy of the Web-inf directory in the project directory/WEBAPPS/EXAMPLES/WEB-INFO/WEB.XM to the/myjspproject/web-info of your project, in the/myjspproject/ Create two folders in Web-info: Classes and lib. The final project directory should look like this:
Test: Browser Input: http://localhost:8080/myJspProject/index.jsp Enter, run the result as follows:
Workaround: Change the browser encoding to the specified encoding:
1.5web-inf Table of Contents detailedThis directory is a secure directory for Java Web applications. The so-called secure directory is that clients cannot access directories that are accessible only to the server. where Web. XML is the project deployment file, Classes directory: Store the *.class file, the Lib directory to store the required jar package. For example: we create a test.html in Web-inf, which we access through the browser:
The Web. XML configuration file can be configured on the Welcome page default Welcome page is the project below the index.jsp, join we need to put the project under the haha.jsp, in/web-inf/web.xml web-app tag add the following code:
1 < welcome-file-list > 2 < Welcome-file >/haha.jsp</welcome-file>3</ Welcome-file-list>
Operation Result:
1.6 Practical Eclipse writing the first Web applicationNote: If you are writing Java Web Apps using Eclipse, you should use the EE version of Eclipse. and configure the Tomcat server Window-preference-server-runtime Environment-add in Eclipse, then create a new JSP file in the WebContent directory and press CTRL + F11 (or right--run on Server in the project) can use the built-in browser to access the established Web site.
1.7 Writing the first Web application with MyEclipseBefore you create a new project, you first configure JRE and Tomcat in MyEclipse. Step Window-preference-java-install Jres-add;window-myeclipse-servers-tomcat (note set the Tomcat JRE and set the server to Enabled).
Next, start the Tomcat server in MyEclipse:
Test home http://localhost:8080/proves Tomcat is up and running, we can launch and publish the Web application in MyEclipse.
New a webproject will generate the following directory structure (by default there is a index.jsp in the Webroot directory).
Publish the WebApp.
1.8 Understanding the project's virtual path
The virtual path is-myeclipse-web on the item that can be modified right-click on the property.
Redeploy, the browser needs to use http://localhost:8080/hello/index.jsp access.
1.7 Modifying the Tomcat default port 2.jsp syntax base 3.jsp built-in object 4.java beans5.jsp State management 6.jsp directive and action element 7.jsp case ProjectJava Web Learning Note-jsp