05.Servlet登录后自动跳转(自动刷新)
2014-05-11 11:23
218 查看
ServletDemo06:
message.jsp:
访问:http://localhost:8080/TestJ2EE/ServletDemo6
则会出现:恭喜你登录成功,立即跳转,然后地址栏变成http://localhost:8080/TestJ2EE/index.jsp,跳转到index,jsp页面
package servlet; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.Random; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ServletDemo06 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String data = "<meta http-equiv='refresh' content='3;url=/j2ee_day01/index.jsp'> 恭喜你登录成功,立即跳转!"; this.getServletContext().setAttribute("data", data); this.getServletContext() .getRequestDispatcher("/message.jsp") .forward(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
message.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% String str = (String)application.getAttribute("data"); out.print(str); %> </body> </html>
访问:http://localhost:8080/TestJ2EE/ServletDemo6
则会出现:恭喜你登录成功,立即跳转,然后地址栏变成http://localhost:8080/TestJ2EE/index.jsp,跳转到index,jsp页面
相关文章推荐
- Servlet定时刷新和页面3秒后自动跳转
- servlet_response自动刷新_实现自动跳转
- servlet实现自动登录,并显示保存的用户信息
- html(对php也有效)页面自动刷新和跳转(简单版本)
- 处理HTTP响应(响应码、响应头、请求重定向、自动刷新/跳转)
- 解决用户退出登录不会自动跳转到登录页面的问题
- php在没有登录的情况下自动跳转到登录页
- 页面定时刷新或自动跳转
- jsp制作计数器,自动登录,定时刷新等简单小应用
- 登陆成功后自动跳转到登录页面的前一个页面
- web前端中的各种注释和自动刷新,自动跳转,no-cache
- 判断用户是否登录,用户在没有登录访问页面时,自动跳转到登录页面(二)
- JavaWeb学习记录总结(二十九)--Servlet\Session\Cookie\Filter实现自动登录和记住密码
- Spring Security登录超时,angular ajax请求出错自动跳转至登录页(jQuery也适用)
- 5分钟App无操作,自动跳转到登录页面
- Linux下使用expect实现跳板机自动跳转/免密登录/自动登录(转)
- servlet相关知识,使用servlet实现定时刷新,实现页面登录次数统计
- xshell 自动登录与自动跳转
- 页面自动刷新,页面自动跳转
- Servlet自动刷新页面