1.要用servlet首先要在application中引入servlet.jar
2.然后要在.java文件中
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.ServletException; import java.io.IOException; import java.io.PrintWriter; //这句import可视具体情况引入
3.介绍一下servlet中的几个常用的方法
a) protected void service(HttpSerlvetRequest req,HttpServletResponse res) throws ServletException,IOException{}
如果被overwrite了,则可能不会调用doXXX method。
b)protected void doGet(HttpSerlvetRequest req,HttpServletResponse res) throws ServletException,IOException{}
特征1:safe and idempotent. 2:Only ASCII (text) data can be sent to server with GET method. 3:easy to bookmarks.
主要作用:获取数据,对数据不作改变
c)protected void doPost(HttpSerlvetRequest req,HttpServletResponse res) throws ServletException,IOException{}
特征1:not safe and idempotent. 2disallow bookmarks.
主要作用:传输form data,大批量的数据,常用在bbs等可改变数据存储的地方
还有一些东西下次再讲吧 |