时间:2021-07-01 10:21:17 帮助过:18人阅读
3)、 code:
[java] package com.johnny.test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorld extends HttpServlet implements javax.servlet.Servlet{
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public HelloWorld() {
super();
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.getWriter().write("Hello, world 1112!");
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
package com.johnny.test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorld extends HttpServlet implements javax.servlet.Servlet{
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public HelloWorld() {
super();
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.getWriter().write("Hello, world 1112!");
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
web.xml
[html]
4)、 右键点击HelloWorld.java,选择rus as :run on server,在浏览器上会显示:Hello, world 1112!
5)、 或者右键点击工程,export MyFirstDynamicWebProject.war,然后放到ubuntu的tomcat的webapps目录下
http://www.bkjia.com/PHPjc/477266.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477266.htmlTechArticle1、 安装eclipse 1)、 在官网上直接下载Eclipse IDE for Java EE Developers,解压即可; 2、 eclipse安装tomcat插件: 1)、 在http://www.eclipsetotale.com/tomcat...