servlet基础
1.编写servlet程序,在页面上输出HelloWorld
要求:
(1)创建项目之后new—class,自行编写servlet程序,覆盖doGet及doPost方法
(2)在web.xml中配置<servlet>及<servlet-mapping>
2.编写servlet程序读取表单中的数据
[html] <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<form method="post" action="ServletTest2">
<input type="text" name="text" />
<input type="submit" value="提交">
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<form method="post" action="ServletTest2">
<input type="text" name="text" />
<input type="submit" value="提交">
</form>
</body>
</html>
[html]
<?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">
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>com.mars.ServletTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/helloworld</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>