IDEA development Java Web environment configuration

1. Build a Tomcat server

Tomcat is a server running Java Web and a container for JSP, so you need to install and configure the server first. On the Tomcat official website https://tomcat.apache.org/download-90.cgi, select the version installation package (Windows64 bit) corresponding to the computer system. The software is green and free to install, so unzip it directly to the directory to be stored

Next, you need to configure the environment variables , as shown below, the new system variable is named CATALINA_HOME, and the value is the Tomcat directory you just unzipped.

After that, there is a startup.bat command file in the Tomcat bin directory. Double-click to start the server . Do not close the window. Enter localhost: 8080 in the browser to see the default home page of Tomcat, indicating successful configuration.

The directory structure of Tomcat is as follows:

We create a new demo folder under the webapps directory and create the homepage file index.jsp under the demo. In addition, the WEB-INF folder is also needed to store information about web applications. This directory is a secure directory for the web and can only be accessed through the server. Create classes under WEB-INF for storing bytecode files generated by compilation, lib folder for storing jar packages, web.xml is a configuration file, you can copy a copy from webapps \ examples \ WEB-INF \ web.xml . After that, you can enter http: // localhost: 8080 / demo / index.jsp in the browser to browse the content of the index.jsp page. The directory structure of the folder is as follows:

demo:   WEB-INF:

The web application can be configured in web.xml , for example, the default homepage of the website is configured, and the default homepage of Tomcat is index.jsp, for example, by configuring the myindex.jsp file as follows

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  version="4.0"
  metadata-complete="true">
  <welcome-file-list>
	<welcome-file>/myindex.jsp</welcome-file>
  </welcome-file-list>
  
</web-app>

Modify the default port number : The default port of Tomcat is 8080. If it conflicts with the existing port, you need to manually modify it to another port. Open the Tomcat / conf / server.xml file, find the following statement, and modify 8080 to another port number.

<Connector port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />

 If the Chinese characters output by the Tomcat console are garbled, you can change the encoding mode, and modify the encoding mode of the console output to GBK in Tomcat / conf / logging.properties:

 Create a new Java Web project using IDEA

Open IDEA and select File-> new-> Project to pop up the following new tab, select Project SDK and project type as follows:

Click next to select the project folder, and then click Finish to create a Web project.

Click File-> Project Structure to configure the SDK, modules, dependencies, and output directory of the project . Click Artifacts in the sidebar to set the output location of the project, set the packaging and deployment of the project, and other configurations can be seen: https://blog.csdn.net/theVicTory/article/details/104682415 .

Set up automatic completion of JSP code : IDEA installs the jsp plugin by default, but there is no code completion upgrade in actual use of jsp. You need to set up the Modules Libraries under Project Structure and add Tomcat:

Finally, configure the Tomcat server operation: Click on the figure in the upper right corner of the interface to open the operation environment configuration

Click + in the upper left corner, select Tomcat Server-> local, then click the Configure button to find the installation directory of Tomcat, then select the default startup browser as FIrefox, and click OK to complete the configuration.

Finally, click the green execute button in the upper right corner of IDEA or the shortcut key Shift + F10 to start this Java web project and display it in the browser

 

Published 124 original articles · Like 65 · Visit 130,000+

Guess you like

Origin blog.csdn.net/theVicTory/article/details/104282873