In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to create and publish projects in Servlet. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Create a publish web project
Specific steps:
1. Create a dynamic web project helloword in the development tool
two。 Create an index.html file in webContent
3. There are two ways to publish an web application to the server:
Method 1: publish manually
(rarely used during development and used when a project is released to a production environment)
Copy the files in the WebContent directory under the web project in workspace to the server webapps directory, and create a new helloword root directory in this directory.
Method 2: auto publish
To automatically publish web applications to web servers, you need to integrate tomcat into the development tools, which can automatically publish and update to the server.
Run helloword
Open a browser to access http:localhost:8080/ helloword/index.html
Example
Under the WEB-INF directory of the new idea project
1. Create a simple landing page login.html
Title account password
two。 Write Servlet programs
Package com.ff.firstWeb.servlet;import javax.servlet.ServletConfig;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException / * servlet build inherits HttpServlet to implement Servlet init service destroy override parent class method * / public class LoginServlet extends HttpServlet {/ * is created when the client accesses LoginServlet for the first time, the creation of the server is called only once, and only one servlet object is created * / public LoginServlet () {System.out.println ("LoginServlet no-parameter constructor"). } / * init (), initialization, after the object is created, after the constructor is executed, call the init method to complete some initialization operations only once how not to initialize the operation, you do not have to rewrite init (), but the server will still call init (), calling the parent class * / @ Override public void init (ServletConfig config) throws ServletException {System.out.println ("init") System.out.println (config.getInitParameter ("count"));} / / provides the server. Each request calls service @ Override protected void service (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println ("service"). } / * before the server shuts down, servlet is called before it is destroyed. Execute only once to complete some final operations in this method: for example, save the log, how the data backup has no final operation, and do not have to rewrite destroy (), but the server will still call destroy (). Call destory () * / @ Override public void destroy () {System.out.println ("destroy") in the parent class }}
Modify the configuration in web.xml
Login com.ff.firstWeb.servlet.LoginServlet count 100 login / login demo.html Thank you for your reading! This is the end of the article on "how to create and publish a project in Servlet". 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, you can share it 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.
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.