上篇博客写的是如何配置好环境,那么现在就该测试一下如何运行效果,检查是否配置成功:
首先建立一个webproject,
新建一个类,并且继承HttpServlet类:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorldServerlet extends HttpServlet{
public void doGet(HttpServletRequest request , HttpServletResponse response)
//doGet方法进行web的请求和回应动作
throws ServletException,IOException{
PrintWriter out = response.getWriter();
out.println("132"); //输送到ie界面的内容
}
}
然后再web.xml中进行配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 我的注释 这里的配置关系到能不能正常访问到servlet类的内容 -->
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.bo.introduct.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/hello/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
然后再Tomcat中加载项目名字,启动tomcat,打开ie,地址栏中写入 http://127.0.0.1:8080/(项目全名)/检测是否能跳转到index界面,测试是否部署成功;此时界面出现index里面的内容,在继续补全地址,http://127.0.0.1:8080/(项目全名)/hello,则会跳转到新界面,显示输出为123;
posted on 2010-12-11 20:42
Soap MacTavish 阅读(503)
评论(0) 编辑 收藏