不一样的思想~~
http://shop34712791.taobao.com
MSN:wins0910@hotmail.com
jsp/servlet/javaBean 小程序
上一篇 /
下一篇 2007-08-28 16:21:26
/ 个人分类:白盒测试
create a tomcat project:test
package:WEB-INF/src/test
test.java and TestBean.java
1、test.java:
package 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 test extends HttpServlet{
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("asdfasdfasdf");
//arg1.sendRedirect("index.jsp");
arg1.sendRedirect("TestBean.jsp");
}
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("asdfasdfasdf");
//arg1.sendRedirect("index.jsp");
arg1.sendRedirect("TestBean.jsp");
}
}
2、TestBean.java:
package test;
public class TestBean{
private String name = null;
public TestBean(String strName_p){
this.name=strName_p;
}
public String setName(String strName_p){
return this.name=strName_p;
}
public String getName(){
return this.name;
}
}
project test 下:index.jsp and TestBean.jsp
3、index.jsp
<html>
<body>
<center>
now time is :<%=new java.util.Date()%>
</center>
</body>
</html>
4、TestBean.jsp
<%@ page import = "test.TestBean"%>
<html>
<body>
<center>
<%
TestBean myBean = new TestBean("This is java bean");
%>
this is java bean name :<%=myBean.getName()%>
</center>
</body>
</html>
5、WEB-INF/web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Welcome to Tomcat</display-name>
<descrīption>
Welcome to Tomcat
</descrīption>
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>test.test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/index.do</url-pattern>
</servlet-mapping>
</web-app>
6、http://localhost/test/index.do
7、jsp/servlet/javaBean test example
收藏
举报
TAG:
碎片
白盒测试