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

Source: Internet
Author: User

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. Hamburg joins http://www.fanzaihanbao.com/Hamburg branch

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"%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >


    
    
<title>my JSP ' index.jsp ' starting page</title>


  
<body>
<form action= "Testservlet" >
Online Tutorials:
<input type= "text" name= "Weburl" size= " [/>]"


<input type= "Submit" value= "Submission"/>
</form>
</body>





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 Step, you also need to add a result.jsp return page. The steps are as follows

The contents of result.jsp are as follows:

<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >


    
    
<title> The result is:</title>


  
<body>
<%=request.getattribute ("Weburl")%>
</body>







13th, you also need to modify the Web. XML (actually just modify the mapping path to <url-pattern>/TestServlet</url-pattern>
), the following modifications are as follows:

<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.5"
xmlns= "Http://java.sun.com/xml/ns/javaee"
xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
<servlet>
<description>this is the description of my EE component</description>
<display-name>this is the display name of my EE component</display-name>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

14th step, OK, we have a project already done, and the following puts the project into tomcat inside running. Click the button in the red circle below the image.








17th, 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.




* Note: This article is transferred from http://jijiaa12345.iteye.com/blog/1739754

 

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

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.