Getting Started with Eclipse development Web project

Source: Internet
Author: User
Tags tomcat

Preface: Has been using MyEclipse 8 to develop the web, today deliberately use eclipse, so in this small note, one can refer to the need, and then make a note to spare

(reprint please indicate source: http://blog.csdn.net/ldw4033/article/details/18313281)1. Building the development environment 1.1. Development toolsJdk:jdk1.6.0_17
Web server:apache-tomcat-6.0.37
Ide:eclipse-jee
1.2. Build the development environmentBy selecting the IDE as a development tool, the IDE can manually configure the required plug-in tools, so it's easy and quick to build a development environment.
(1) Installing the JDKTip: You need to configure environment variables after you install the JDK.
(2) Installing TomcatTip: If the decompression version is directly decompressed OK, if the installation version needs to follow the installation instructions to complete the installation. Because you are using the IDE for development, you do not need to configure the Tomcat environment variables, but it is recommended that you do not rely too much on the IDE.
(3) Unzip EclipseTip: If you do not have a JDK installed, you cannot complete the installation of Eclipse.
Okay, here's the development environment ready, then use a demo to demonstrate how to develop Web projects in eclipse.
2. Developing Web Projects 2.1. Create a new Web projectEclipse-->file-->new-->dynamic Web Project, as shown in Figure 1:
Figure 1 If there is no or eclipse-->file-->new-------->web-->otherdynamic Web Project, as shown in Figure 2, 3:


Fig. 2 Fig. 3
Select New runtime under Target runtime to configure the Web Server

Next>
Select the Tomcat installation directory via browse
Finish>
After that, all the way next until finish is OK.
The new Web project structure is as follows
2.2. Developing ServletsRight-click on SRC on Project Explorer view to select New-->servlet
Next>

Choose to override the service method, which automatically generates code to make it easier
Of course, you can write the servlet all manually, but don't forget to configure the servlet in Web. XML, hehe ^_^
Then finish completes the creation of the servlet.

Helloservlet.java source code is as follows

Package com.lanyoung.servlet;
Import java.io.IOException;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;

Import Javax.servlet.http.HttpServletResponse;  /** * Servlet Implementation Class HelloServlet */public class HelloServlet extends HttpServlet {private static final
       
    Long serialversionuid = 1L;
    /** * @see httpservlet#httpservlet () */public HelloServlet () {super (); }/** * @see httpservlet#doget (httpservletrequest request, httpservletresponse response) */protected void doget (Ht Tpservletrequest request, HttpServletResponse response) throws Servletexception, IOException {System.out.println ("
	Hello JSP "); }/** * @see httpservlet#dopost (httpservletrequest request, httpservletresponse response) */protected void DoPost ( HttpServletRequest request, HttpServletResponse response) throws Servletexception, IOException {this.doget (request, RE
	Sponse); }

} 

Demo code is so simple, hehe ^_^
2.3. Publish Web Project The Web project is created, and the next task is to publish the Web project in Web server
Window-->show Views-->servers
in Servers view blank area right
New-->server
 



 
 
After finish, you can start Tomcat under servers.
  Start Tomcat will print a lot of tomcat boot messages under console
If no exception appears, the demo publication is successful
Even if there is a warning message
Access Http://localhost:8080/HelloWorld/HelloServlet
in the browser if no exception information is present, and the
Hello JSP is output in the console
indicates that the servlet test was successful ^_^
just made a very simple demo that says the problem is OK
2.4. Developing JSP Create a new JSP File
in the WebContent directory  
 
Next> after the direct finish
Index.jsp source code is as follows

<%@ page language= "java" contenttype= "text/html; Charset=iso-8859-1 "
    pageencoding=" iso-8859-1 "%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Re-deploy the demo project and you'll see the effect.

(reprint please indicate source: http://blog.csdn.net/ldw4033/article/details/18313281)
Above..
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.