见博客图片相册
通过启动停止服务,调试tomcat程序,
发布工程的界面
指明Tomcat server, windowsàpreference
除此之外
1.拷贝或者安装 Tomcat文件夹到比如:d:/test/tomcat6
运行 startup.bat或者tomcatw6(右键属性选择在兼容模式下运行)
配置操作系统环境变量
添加JAVA_HOME:jdk的物理路径
2.在myeclipse中
windows--->preference-->Myeclipse-->servers-->Tomcat--->tomcat6.x
enable
homedirectory:d:/test/tomcat6
应用
3.project--->build automatically
4.启动tomcat后,
通过访问:http://localhost:8080
可以设置tomcat manager,用户名口令:admin admin
///
MyServerlet.java文件
Package abcd;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.commons.logging.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.util.List;
import java.io.*;
public class MyServerlet extends HttpServlet implements ServletContextListener {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
public MyServerlet() {
super();
}
private static final Logger log = Logger.getLogger(MyServerlet.class);
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doDelete method of the servlet. <br>
*
* This method is called when a HTTP delete request is received.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doDelete(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
List<Integer> list=new ArrayList<Integer>();
list.add(1);
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
/**
* Returns information about the servlet, such as
* author, version, and copyright.
*
* @return String information about this servlet
*/
public String getServletInfo() {
return "This is my default servlet created by Eclipse";
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
//System.out.println("fffffffffffffffffffffffffff");
}
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
}
public void contextInitialized(ServletContextEvent arg) {
此处加入你希望运行的程序,类似main方法内容
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
///
Web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>MyServerlet</servlet-name>
<servlet-class>abcd.MyServerlet</servlet-class>
</servlet>
<listener><listener-class>abcd.MyServerlet</listener-class></listener>
<servlet-mapping>
<servlet-name>MyServerlet</servlet-name>
<url-pattern>/serverlet/MyServerlet</url-pattern>
</servlet-mapping>
</web-app>