この記事では、Javaの応答オブジェクトの使用について説明します。次のように、参照のために共有してください。
<jsp:forward>アクション要素は、現在のページから指定されたページに実行して移動するときに、サーバー側の現在のページの実行を終了するために使用されます。
応答オブジェクトのsetheader()メソッドを使用して、ページの自動更新時間間隔を設定します。このページを60秒ごとにリロードすることを実装する声明は、次のとおりです。
コードコピーは次のとおりです。Response.setheader( "Refresh"、60);
3秒後、新しいページをロードするブラウザのステートメント//www.vevb.comは次のとおりです。
コードコピーは次のとおりです。Response.SETHEADER( "REFRESH"、 "3; url = // www.vevb.com");
応答の方法:void sendredirect(string url)は、指定されたURLアドレスにページをリダイレクトします。
例:応答を使用して、ユーザーログイン機能を実装します
login.htmlはログインフォームページです
login.jspは、ユーザーのログインが成功したかどうかを確認するための情報処理ページです。
success.jspは、ログインが成功した後のジャンプページです。
login.htmlのソースコードは次のとおりです。
<!doctype html public " - // w3c // dtd html 4.01 transitional // en"> <html> <head> <title>ログイン関数インスタンス</title> <meta http-equiv = "keywords" content = "keyword1、keyword2、keyword3" http-equiv = "content-type" content = "text/html; charset = utf-8"> <! - <link rel = "styleSheet" type = "text/css" href = "./ styles.css" type = "text" name = "name"> <br>パスワード:<入力タイプ= "パスワード" name = "pwd"> <br> <br> <input type = "submit" name = "login" balue = "login"> <入力タイプ= "reset" name = "reset" value = "reset"> </form> </center> </body> </html> </html> <
login.jspのソースコードは次のとおりです。
<%@ page Language = "Java" Import = "Java.util。*" contentType = "text/html; charset = utf-8"%> <%string path = request.getContextPath = request.getScheme()+"://"+request.getServername()+" html public " - // w3c // dtd html 4.01 transitional // en"> <html> <head> <base href = "<%= basepath%>"> <title> login function instance </title> <meta http-equiv = "pragma" content " content = "no-cache"> <meta http-equiv = "compers" content = "0"> <meta http-equiv = "keywords" content = "keyword1、keyword2、keyword3"> <meta http-equiv = "description" content = "this is my page"> <! href = "styles.css"> - > </head> <body> <center> <h1> login function instance </h1> <%request.setcharacterencoding( "utf-8");文字列名= request.getParameter( "name");文字列pwd = request.getParameter( "pwd"); if(name!= null && pwd!= null && name.equals( "guanlin")&& pwd.equals( "123")){//response.sendredirect("success.jsp "); %> <jsp:forward page = "success.jsp"> </jsp:forward> <cent} Response.setheader( "REFRESH"、 "5; url = login.html"); }%> </center> </body> </html>Success.jspのソースコードは次のとおりです。
<%@ page Language = "Java" Import = "Java.util。*" contentType = "text/html; charset = utf-8"%> <%string path = request.getContextPath = request.getScheme()+"://"+request.getServername()+" html public " - // w3c // dtd html 4.01 transitional // en"> <html> <head> <base href = "<%= basepath%>"> <title> login function instance </title> <meta http-equiv = "pragma" content " content = "no-cache"> <meta http-equiv = "compers" content = "0"> <meta http-equiv = "keywords" content = "keyword1、keyword2、keyword3"> <meta http-equiv = "description" content = "this is my page"> <! href = "styles.css"> - > </head> <body> <center> <h1 style = "green">正常にログイン!</h1> <%request.setcharacterencoding( "utf-8");文字列名= request.getParameter( "name");文字列pwd = request.getParameter( "pwd"); %>ログインしたユーザー名は次のとおりです。
この記事がみんなのJavaプログラミングに役立つことを願っています。