Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of JavaWEB Development

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain the example analysis of JavaWEB development for you in detail. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

WEB, which means web in English, is used to indicate the resources on the Internet host that are accessible to the outside world.

The Web resources accessible to the outside world on Internet are as follows:

Static web resources (such as html pages): the data in the web page that people browse is always the same.

Dynamic web resources: the data in the web page for people to browse is generated by the program, and the content is different when visiting the web page at different time points.

Static web resource development technology

Html 、 CSS 、 javaScript

Commonly used dynamic web resource development techniques:

JSP/Servlet, ASP, PHP, etc.

In Java, dynamic web resource development technology is collectively referred to as Javaweb.

WEB server

To learn web development, you need to install a web server first, and then develop corresponding web resources in the web server for users to access by browsers.

Note: the server here does not refer to the server hardware resources, but to the server software.

1. Common WEB servers

WebLogic, a product of BEA, is the most widely used Web server at present, which supports J2EE specification and is constantly improved to meet the new development requirements.

Another commonly used Web server is IBM's WebSphere, which supports the J2EE specification.

In small applications or systems with special needs, you can use a free Web server: Tomcat, which supports all JSP and Servlet specifications.

2.Tomcat server

Tomcat official site: http://tomcat.apache.org/

Get the Tomcat installer package

The tar.gz file is the installed version of the Linux operating system

The exe file is the installed version of the Windows system

Zip file is a compressed version of Windows system.

Install Tomcat: unzip the package.

3. Start the Tomcat server

Double-click the startup.bat file in the bin directory

Enter http://localhost:8080/, and the following interface indicates that the installation is successful

4. Common startup problems

1. Java_home environment variable

Set the JAVA_HOME environment variable to the home directory of JDK, and you can start Tomcat using the startup.bat file.

2. Port occupancy problem

Netstat-ano command to view the process pid that occupies the port, and then close it with the task manager

3. Catalina_Home environment variable: specify which tomcat to start when tomcat starts. Generally, configuration is not recommended.

4. Not recommended-modify tomcat/bin/server.xml and change the default port to 80

Tomcat directory structure _ WEB application, virtual host configuration

Directory structure of 1.tomcat

Directory where the bat files needed for bin startup and shutdown are located

Conf configuration directory

The directory where the jar package required by the lib tomcat runtime is located

The directory where the logs log files are located

The temporary files generated by temptomcat runtime are stored in a directory that does not need to be managed by us.

The most commonly used directory in webapps development, where web applications can be directly accessed by browsers.

Work working directory, where the working files generated by the tomcat runtime are stored

two。 Virtual host / web application

1), virtual host:

A tomcat can be configured with multiple sites.

You can think of these sites as virtual hosts for tomcat servers.

A website can be thought of as a virtual host, such as http://localhost.

2), web application:

There will be many web resources in a virtual host.

Organize all the web resources related to a function into a web application and then give it to the virtual host.

3. Configure web applications for virtual hosts

Take the virtual host localhost as an example to configure the web application:

(1) in the tag of conf\ server.xml, configure the label.

This configuration requires restarting the server, which is not recommended

1. Write the value of path to the address bar of the browser, and you can find the virtual path mapping of the WEB application, * web application.

Http://localhost:8080/news/new1.html

2. The value of docBsse is the real address of the WEB application.

3. If path is set to empty, the web application is the default web application.

The default web application accesses the resources of the web application without writing the name of the web application.

Http://localhost:8080/new1.html

(2) write a xml file in tomcat\ conf\ Catalina\ localhost in this directory.

No need to restart the server

1. The name of the xml file is the virtual path of the web application.

2. You can configure the tag in this xml, as long as you configure the docBase attribute = real path. E:\ tomcat\ conf\ Catalina\ localhost\ news2.xml file

3. If there is / in the configured virtual path, the xml file name is replaced by # /.

Http://localhost:8080/news/xxx/new1.html

The xml file is named news#xxx

4. If the file name is set to ROOT.xml, the web application described by xml becomes the default web application.

(3) directly place the web application news in the directory managed by the virtual host

E:\ Program-Files\ apache-tomcat-7.0.11\ webapps

The folder name of the web application is the virtual path, http://localhost:8080/news/1.html

As long as the name of the web application folder is changed to ROOT, the web application is the default web application.

Home page configuration of 5.localhost virtual host

1. Name the folder applied by web ROOT

E:\ Program-Files\ apache-tomcat-7.0.11\ webapps\ ROOT

2. Configure the web.xml file under ROOT\ WEB-INF

Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version= "3.0" >

Index.html

6. Configure virtual host: 1. Configure a virtual host under the tag in E:\ tomcat\ conf\ server.xml to add a virtual host to tomcat.

Name-specifies the name of the virtual host through which the browser accesses the virtual host

AppBase-the directory managed by the virtual host. The current virtual host of web applications placed in this directory can be loaded automatically.

2. * when the browser accesses the address, it needs to translate the address into the corresponding ip to find the server, in which the translation process is implemented by the dns server.

You can use hosts files to simulate the function of dns, thus completing the experiment.

C:\ Windows\ System32\ drivers\ etc\ hosts

# localhost name resolution is handled within DNS itself.

# 127.0.0.1 localhost

#:: 1 localhost

127.0.0.1 www.mytaobao.com

3. * default virtual host: if the visitor is accessing through ip, the server cannot tell which virtual host resources are currently being accessed, and visit the default virtual host.

The default virtual host can be configured through the defaultHost attribute on the engin tag in server.xml.

Piecemeal knowledge

1. Pack war packets to reduce the size of web applications and facilitate transmission, and under the directory managed by virtual host, war can be decompressed automatically by default

1. Find the folder of web application E:\ mytaobao\ ROOT > jar-cvf ROOT.var * in the cmd window.

2. the second method is to select the file, right-click to compress, .zip, and then modify the compressed file name. War

2. Conf\ web.xml is the parent class web.xml of all web applications. Some web applications do not have web.xml, but can inherit conf\ web.xml.

3. General conf\ context.xml configuration

WEB-INF/web.xml

Monitor for changes in the WEB-INF/web.xml file, and the web application needs to be reloaded.

4. Equipped with the reloadable element of the context element, let tomcat automatically load the updated web application. When the java dynamic resources are modified, there is no need to restart, and the server will load again automatically. The development stage can be matched, but not when it is online.

5. The management platform of Tomcat server

On the left side of Tomcat's home page, there is Tomcat Manager option, no username and password, click OK, go to conf\ tomcat-users.xml to match users.

This is the end of this article on "sample Analysis of JavaWEB Development". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report