当前页面: 开发资料首页 → JSP 专题 → 图解利用Eclipse3+Sysdeo Tomcat plugin编辑和调试JSP(3)
图解利用Eclipse3+Sysdeo Tomcat plugin编辑和调试JSP(3)
摘要: 图解利用Eclipse3+Sysdeo Tomcat plugin编辑和调试JSP(3)
图解利用Eclipse3+Sysdeo Tomcat plugin编辑和调试JSP(1)
图解利用Eclipse3+Sysdeo Tomcat plugin编辑和调试JSP(2)
五. 编辑Servlet程序
在成功编辑和调试JSP的基础上,再进行编辑和调试Servlet程序就比较简单了。
1. 先停止Tomcat服务器。 右击“WEB-INF/src”目录,新建->类,
填写包名:“javamxj.tomcat.servlet”
填写类名:“ServletSample”
点击完成。
2. 修改ServletSample.java如下:
<table style="WIDTH: 614px; HEIGHT: 454px" borderColor=#000000 cellSpacing=0 cellPadding=4 width=614 border=0>
<tr>
<td style="BORDER-BOTTOM: rgb(51,51,204) thin inset" vAlign=top width="100%" bgColor=#d9eaf2 height=33>
ServletSample.java
</td></tr>
<tr>
<td style="BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: rgb(236,233,216)" vAlign=top width="100%" bgColor=#edf2b8>
/*
* 创建日期 2004-10-18
* 作者 javamxj (CSDN Blog)
*/
package javamxj.tomcat.servlet;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class ServletSample extends HttpServlet {
private String s;
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
PrintWriter out = res.getWriter();
String s="Hello, javamxj Blog!";
out.println(s);
out.close();
}
} </td></tr>
</table>
3. 在WEB-INF目录下建立一个web.xml文件,保存文件。
<table style="WIDTH: 627px; HEIGHT: 352px" borderColor=#000000 cellSpacing=0 cellPadding=4 width=627 border=0>
<tr>
<td style="BORDER-BOTTOM: rgb(51,51,204) thin inset" vAlign=top width="100%" bgColor=#d9eaf2 height=33>
WEB-INF/web.xml
</td></tr>
<tr>
<td style="BORDER-TOP-STYLE: none; BORDER-TOP-COLOR: rgb(236,233,216)" vAlign=top width="100%" bgColor=#edf2b8>
<?xml version="1.0" encoding="ISO-8859-1"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
ServletSample
javamxj.tomcat.servlet.ServletSample
ServletSample
/ServletSample
</td></tr>
</table>