Get started with creating a Java Web Project under MyEclipse (illustrated) Classic tutorial

Source: Internet
Author: User

http://jijiaa12345.iteye.com/blog/1739754 to create a Java Web project under MyEclipse (illustrated) Classic Tutorial This article is a beginner's tutorial on building a Java Web project under MyEclipse. Illustrated, very detailed. The version of MyEclipse used is 7.5. First step: Create a new web Project, such as. In the second step, fill in the popup window below. Project name fills in the item names; specification Level select Java EE 5.0 and click on the "Fininsh" button to proceed to the next step. The third step is to create a new project structure such as. The project contains several packages, one SRC, one webroot, and the JRE ... and Java EE ... The two are the classes that the project relies on (temporarily). We mainly look at the webroot,jsp page we put in this directory. Fifth step, build the Servlet class. Press action. Sixth step, fill in the name of the Servlet class in name: Testservlet. , below the multiple options, we remove the other, just choose dopost (). Seventh step, fill out the above steps, click on the "Next" button, came to the following. Here, we don't have to fill in anything. Let's parse the contents of this. This means that we will create a Testservlet class and also modify the associated mapping path in the Web. xml file. The mapping path is initially "Servlet/testservlet". Click "Finish" button to complete the operation. The eighth step, we see the following page, SRC more than one Testservlet.java file. We are going to modify this page. In the Nineth step, we will revise the Testservlet as follows. Remove the miscellaneous ones. and modify the Dopost method name to service. See figure two below. Tenth step, we also modify the index.jsp, see the following two photos. The code is as follows: <%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%> <title>My JSP ' index.jsp ' starting page</title> The 11th step, and then write the logic into the Testservlet.java inside (such as). The code is as follows: Import Java.io.ioexception;import Java.io.printwriter;import Javax.servlet.requestdispatcher;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;public class TestServlet Extends HttpServlet {public void service (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {String weburl = Request.getparameter ("Weburl"); if (weburl!=null&& Weburl.equals ("http://www.w3csschool.com")) {Request.setattribute ("Weburl", "you entered the online Web Tutorial Network");} else{Request.setattribute ("Weburl", "The URL you entered is not recorded in the database");} RequestDispatcher dispatcher = Request.getrequestdispatcher ("result.jsp"); Dispatcher.forward (request, response); }} 12th, you also need to add a result.jsp return page. The following steps are result.jsp: <%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%> <title>The result is:</title> <%=request.getattribute ("Weburl")%>In the 13th step, you need to modify the Web. XML (actually just modify the mapping path to /testservlet ), the following modifications are as follows: This is the description of my EE component This is the display name of my EE component testservlet testservlet testservlet /testservlet index.jsp 14th step, OK, we have a project already done, below put the project loaded tomcat inside run. Click the button in the red circle below the image. 15th step, the following page appears. Click the "Add" button. 16th step, select the "MyEclipse Tomcat" option. Click the "Finish" button. 17th Step, click on the "OK" button. 18th step, everything is ready, below we start Tomcat server, look at the effect. After clicking "Start", we see a series of information printed below the console, "the Server startup in 1114 MS" information proves that we have successfully started. We clicked on the "Servers" section. Under the Servers column, we found "MyEclipse Tomcat [Default]", click Expand, Find the project name "Myfirstweb", right click, see "Open in Browser" option, click this. See the following two pages for detailed steps. We see that the page has been successfully opened, such as. Enter the content. OK, we see the result, which means that the Java Web project we built is running successfully.

Get started with creating a Java Web Project under MyEclipse (illustrated) Classic tutorial

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.