request对象和response对象(9)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-10 12:18 点击:次
p>
p>import java.io.IOException;
p>import javax.servlet.ServletException;
p>import javax.servlet.http.HttpServlet;
p>import javax.servlet.http.HttpServletRequest;
p>import javax.servlet.http.HttpServletResponse;
p>
p>public class RequestDemo3 extends HttpServlet {
p>
p> //防盗链
p> public void doGet(HttpServletRequest request, HttpServletResponse response)
p> throws ServletException, IOException {
p> //通过getHeader获得referer头信息
p> String referer = request.getHeader("referer");
p> //判断头信息可以知道是不是盗链
p> response.setContentType("text/html;charset=utf-8");
p> if(referer == null || !referer.startsWith("http://localhost")){
p> //盗链
p> response.getWriter().println("是盗链");
p> }else{
p> //不是盗链
p> response.getWriter().println("真不是盗链");
p> }
p> }
p>
p> public void doPost(HttpServletRequest request, HttpServletResponse response)
p> throws ServletException, IOException {
p> doGet(request,response);
p> }
p>}
p>复制代码
p>4.获取客户机请求参数
p>
p>常用API四个
p>
p>getParameter
p>
p>getParameterValues
p>
p>getParameterNames
p>
p>getParameterMap
p>
p>eg:
p>
p>复制代码
p><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
p><html>
p> <head>
p> <title>request.html</title>
p> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
p> <meta http-equiv="description" content="this is my page">
p> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
p> </head>
p>
p> <body>
p> <h1>分别以get和post方式提交数据</h1>
p> <h1>第一种:通过超链接提交数据以?方式</h1>
p> <a href="/Request/servlet/RequestDemo4?name=zhangsan&city=shenzhen">超链接提交数据</a>
p> <h1>第二种:通过form的post方式提交数据</h1>
p> <form action="/Request/servlet/RequestDemo4" method="post">
p> 姓名<input type="text" name="name" /><br/>
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>