Eclipse creating a JSP Web project and Getting Started sample

Source: Internet
Author: User

Eclipse is an open-source, Java-based, extensible development platform. For its part, it is just a framework and a set of services for building a development environment through plug-in components. Fortunately, Eclipse comes with a standard set of plugins, including Java development tools (Java Development kit,jdk).

This article is about the creation of the JSP Web project under Eclipse and the introductory example, under the reference of interested students.

Eclipse is an open-source, Java-based, extensible development platform. For its part, it is just a framework and a set of services for building a development environment through plug-in components. Fortunately, Eclipse comes with a standard set of plugins, including Java development tools (Java Development kit,jdk).

Step 1: Create a new Dynamic Web site project and configure the servlet server

Start Eclipse, create a new project, select Dynamic Web Project in the wizard that creates the new project,



Click "Next", enter the next step of the wizard, type the name of the project, type "MyWebApp" here, and then set up the servlet server, where you need to set Tomcat 6.0 already installed as the default server for the Eclipse's debug servlet program.
Set the method to click "New ..."



In the next dialog box, select Tomcat v6.0,




Click "Next" to go to the next step of the wizard, click "Browse ...", set the installation path for Tomcat 6.0, set it up and click "Finnish" to complete the servlet server Setup.



After the servlet server is set up successfully, eclipse will display the information, click "Finish" to complete the New Project Wizard!



After the success of the Dynamic Web site project, the display of Eclipse and the function of each icon are displayed:

Step 2: Create a new servlet program and debug The program:
Like a normal Java project, you need to create a new servlet class file, right-click on the project icon "MyWebApp", select "new", "servlet",



In the wizard dialog box that pops up, enter the newly created servlet class name "Echoform" and click "Finish" to complete the new servlet class.


After setting up the Servlet class, edit the program in the program editor, follow the input of example 1-3, click the Run button in the toolbar, and then run the program:

Echoform.java:
Import javax.servlet.*;
Import javax.servlet.http.*;
Import java.io.*;
Import java.util.*;
Eclipse runs Sevlet and Jsppublic class Echoform extends httpservlet{

public void Service (HttpServletRequest req, httpservletresponse Res)
Eclipse runs Sevlet and JSP throws ioexception{
Res.setcontenttype ("text/html");

PrintWriter out = Res.getwriter ();

Enumeration flds = Req.getparameternames ();

Eclipse runs Sevlet and JSP if (!flds.hasmoreelements ()) {

Out.print ("Out.print ("<form method=\" post\ "" + "action=\" echoform\ ">");
for (int i = 0; i <; i++)
Out.print ("<b>field" + i + "</b>" +
"<input type=\" text\ "" + "size=\" 20\ "name=\" Field "
+ i + "\" value=\ "value" + i + "\" ><br> ");
Out.print ("<input type=submit name=submit value=\" submit\ "></form>
Eclipse runs Sevlet and JSP}else{

Out.print ("
Eclipse runs Sevlet and JSP while (Flds.hasmoreelements ()) {
String field= (String) flds.nextelement ();
String value= req.getparameter (field);
Out.print (field + "=" + value+ "<br>");
}
}

Out.close ();

}
}





When you run the program, a dialog box pops up to select the server running the servlet, select Create a servlet server and click "Finish".



If Tomcat has been set up to see how the servlet program works, it is actually running an IE browser as a client in eclipse, which can be "Field0" ... Enter some text in each input box and click "Submit" to see the effect


Of course, you can also run the program at the same time, open a Web browser such as IE, and then enter "Http://localhost:8080/MyWebApp/EchoForm" in the Address bar, you can see the same running effect



After debugging, you need to stop the servlet server (TOMCAT):


Step 3: Create a new JSP file and run:

Also right-click on the icon for the "MyWebApp" Item and select "New"-"JSP"




In the wizard dialog box that pops up, enter the new JSP filename "currenttime.jsp", the idea is to enter the full name of the file (that is, include the file extension), then click "Finish" to build the JSP file



In the Eclipse file editor, modify the newly created "currenttime.jsp", insert a line of JSP code, and then click the Run button in the toolbar to see how it works

<%=system.currenttimemillis ()/1000%>






Eclipse creating a JSP Web project and Getting Started sample

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.