In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to create and deploy JavaWeb programs in IDEA". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to create and deploy JavaWeb programs in IDEA" can help you solve the problem.
Create a project
Create a new Java project
To do this, go to File-> New-> Project, then select the Java option on the left and click Next by default.
Select whether to create from a template
If unchecked, the project created at this time is an empty project. If checked, the simplest template program will be created. If you don't check it by default, click Next to proceed to the next step.
Set the project name
Here, you need to set your own project name and the location where the project is stored. Project name is the project name and Project location is the project storage address. Don't worry about More Settings, it will change automatically when we set up the project name and the project storage address. Once set up, click Finish directly.
Add Web support
After the project was created, we found that it was no different from the previous Java SE project, but to turn the project into a Java Web project, we needed to add Web support. To do this, right-click the project and select the Add Framework Support tab.
Then the following options will appear for us to choose from, just check Web Application here, and finally click OK to finish.
Project catalog
After completing the above steps, a blank Java Web project is created. The created project directory is as follows. Here, an index.jsp file will be automatically generated under the web directory. Now everyone has basically abandoned jsp, so we usually choose to delete it.
D:\ personal file\ code\ IDEA\ JAVAWEB-IDEA-DEMO ├─ src └─ web └─ WEB-INF
Configure Tomcat
Click the Add Configuration of the toolbar and the Run/Debug Configurations window pops up
Click the + sign in the upper left corner, select Local under Tomcat Server, and be careful not to select Local under TomEE Server.
Configure related properties
The main configuration here is Name, that is, the name of our Tomcat server, which can be kept by default or set to your favorite name.
Application Serveer, which is the path to our local Tomcat installation.
If After launch is checked, the project home page will be automatically opened in the browser after the project is running, where the browser can choose according to its usual usage.
URL, which is the URL that is opened by default after running.
Finally, you generally need to click Fix,IDEA in the lower right corner to automatically configure the virtual path Application context of the project.
After clicking the Fix step above, it will automatically jump to the Deployment tab, and the URL under Server will change to the following form:
Http://localhost:8080/javaweb_idea_demo_war_exploded/
It is troublesome to visit the project home page here. In order to facilitate access to our project directly through http://localhost:8080, we need to do the following configuration.
First, the Application Context under the Deploy tab is changed to /.
Then change the URL under the Server tab to:
Http://localhost:8080/
Note the following settings. In order to achieve hot deployment, we usually choose On Update action as Redeploy and On frame deactivation as Update classes and resources. In this way, once there are code changes after deployment, IDEA will automatically redeploy our project without having to restart the server for real-time updates. In addition, the JRE setting here defaults to using the JRE version of the project, and if you want to set it separately, you can change it here.
Authentication acc
As we said earlier, after we create a new project and add Web framework support, an index.jsp is generated by default and we need to delete it.
In order to verify whether our program is configured successfully, we need to run it for verification. Here, we choose to create an index.html to access the page after the project is started. If the expected content appears, the project deployment is successful, otherwise the deployment failed.
The index.html is as follows:
Home page
Hello, I'm Murrayuyao.
Then start our IDEA project, and the following information will be printed in the console:
At the same time, the browser will automatically pop up to access our index.html. If the information in the following figure appears correctly in the browser, our project creation and deployment will be successful.
Be careful
Generally speaking, after completing the above steps, our project will be created, deployed, and run successfully. However, there are still a few points to pay attention to, which are explained here.
Compile output directory
By default, the result of the project compilation output is in the project's out directory, and if we want to change it to a custom path, we need to set it ourselves.
Our general customization is to create a classes directory under the WEB-INF directory, then go to File-> Project Structure, select the Modules tab in the project settings, select Use module compile out path under the Paths tab on the right, and set Output path to the classes directory we created.
Project access port
By default, IDEA assigns an interface of 8080 to each new project, and if we want to customize it, we need to be careful when configuring Tomcat, as follows.
That's all for "how to create and deploy JavaWeb programs in IDEA". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.