实现重定向页面
使用response對象提供的sendRedirect()方法可以將網頁重定向到另一個網頁
sendRedirect()方法的語法格式:
response.sendRedirect(String path);
參數說明:
path:用于指定目標路徑,可以是相對路徑,也可以是不同主機的其他URL地址
例如
response.sendRedirect(“login.jsp”)//重定向到login.jsp頁面
response.sendRedirect(“https://www.baidu.com/”)//重定向到百度頁面
創建index.jsp頁面,調用response對象的sendRedirect()方法重定向到login.jsp頁面
login.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>用戶登錄</title> </head> <body> <form name="form1" method="post" action="">用戶名:<input type=text" name="name" id="name" style="width:120px"><br>密 碼<input name="pwd" type="password" id="pwd" style="width:120px"><br><br><input type="submit" name="Submit" value="提交"> </form> </body> </html>總結
- 上一篇: 通过cookie保存并读取用户登录信息
- 下一篇: 通过Application对象实现网站计