Tomcat HelloWorld Servlet with Eclipse
http://www.idimmu.net/2009/03/11/tomcat-helloworld-servlet-with-eclipse/
安裝 Eclipse IDE for Java EE Developers 和 Tomcat
1. Go to New->Project
2. Select ‘Dynamic Web Project’
3. Set ‘Project Name’ to ‘helloworld’
4. Create a ‘New’ ‘Target Runtime’
5. Select ‘Apache Tomcat v7.0′
6. Select the Tomcat Installation Directory you extracted Tomcat to earlier.
7. Then click ‘Finish’ to create the project.
8. Go to File->New->Servlet
9. Enter ‘HelloWorld’ as the ‘Class name’
10. Click ‘Finish’
11. A new ‘HelloWorld.java’ file will be created with most of the work done for you!
Look at all the shiny code the IDE has already written for you!
import java.io.PrintWriter;
Insert the following code in to the doGet function stub:
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("");
pw.println("");
pw.println("");
pw.println("<h1>Hello World</h1>");
pw.println("");
Go to the ‘Run’ menu and select ‘Run’ or press Ctrl+F11 to build the servlet, deploy it to Tomcat and run it!
http://localhost:8080/helloworld/HelloWorld
沒有留言:
張貼留言