- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- String referer = request.getHeader("referer");
- if(referer==null || !referer.startsWith("http://localhost")){
- response.sendRedirect("/day6/index.jsp");
- return;
- }
- response.setCharacterEncoding("UTF-8");
- response.setContentType("text/html;charset=UTF-8");
-
-
- String data = "采访凤姐日记";
- response.getWriter().write(data);
- }
复制代码- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
-
- <title>My JSP 'index.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- </head>
-
- <body>
- <a href="/day6/servlet/ResponseDemo3">查看图书</a></br>
- <a href="/day6/servlet/ResquestDemo4">看凤姐</a></br>
- <a href="/day6/servlet/RequestDemo1">查看URL</a>
- </body>
- </html>
复制代码
第一次输入的时候会跳转到主页去,从主页点了就出现404了
|