이 기사에서는 Java의 응답 객체 사용에 대해 설명합니다. 다음과 같이 참조에 대해 공유하십시오.
<jsp : forward> action 요소는 실행할 때 서버 측에서 현재 페이지의 실행을 종료하고 현재 페이지에서 지정된 페이지로 이동하는 데 사용됩니다.
응답 객체의 Setheader () 메소드를 사용하여 페이지의 자동 새로 고침 시간 간격을 설정하십시오. 60 초 마다이 페이지를 다시로드하는 진술은 다음과 같습니다.
코드 사본은 다음과 같습니다. response.setheader ( "Refresh", 60);
3 초 후, 새 페이지를로드하는 브라우저의 명세서 //www.vevb.com은 다음과 같습니다.
코드 사본은 다음과 같습니다. response.setheader ( "새로 고침", "3; url = // www.vevb.com");
응답 방법 : void sendRedirect (String URL)는 페이지를 지정된 URL 주소로 리디렉션합니다.
예 : 응답을 사용하여 사용자 로그인 기능을 구현하십시오
login.html은 로그인 양식 페이지입니다
login.jsp는 사용자 로그인이 성공했는지 확인하기위한 정보 처리 페이지입니다.
success.jsp는 로그인이 성공한 후 점프 페이지입니다.
로그인의 소스 코드 .html은 다음과 같습니다.
<! docType html public "-// w3c // dtd html 4.01 전환 // en"> <html> <head> <title> 로그인 함수 인스턴스 </title> <meta http-equiv = "keywords"content = "keyword1, keyword2, keyword3"> <meta http- equev-equequiv = "thistat" http-equiv = "content-type"content = "text/html; charset = utf-8"> <!-<link rel = "stylesheet"type = "text/css"href = "./ styles.css">-> </head> <body> <center> <h1> login interface </h1> <comple action = "gogin. <입력 유형 = "text"name = "name"> <br> 비밀번호 : <입력 유형 = "password"name = "pwd"> <br> <input type = "제출"name = "value ="login "> <input type ="name = "value"value = "Reset"> </form> </body> </html> </html>
로그인의 소스 코드는 다음과 같습니다.
<%@ page language = "java"import = "java.util.*"contenttype = "text/html; charset = 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 href = <%= basepathent> "> 인스턴스 </title> <meta http-equiv = "pragma"content = "no-cache"> <meta http-equiv = "cache-control"content = "no-cache"> <meta http-equiv = "meta http-equiv ="contain "> <meta http-equiv ="keyword1, keyword2, keyword2, keyword2. http-equiv = "description"content = "this my page"> <!-<link rel = "stylesheet"type = "text/css"href = "styles.css">-> </head> <center> <h1> 로그인 함수 인스턴스 </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 : "success.jsp"> </jsp : forward> <%} else {out.println ( "<font color = 'red'> username 또는 비밀번호가 잘못되었고 5 초 안에 로그인 페이지로 돌아갑니다. <a href = '응답/login.html'> 로그인 </font>"); response.setheader ( "새로 고침", "5; url = login.html"); } %> </center> </body> </html>Source Code of Success.jsp는 다음과 같습니다.
<%@ page language = "java"import = "java.util.*"contenttype = "text/html; charset = 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 href = <%= basepathent> "> 인스턴스 </title> <meta http-equiv = "pragma"content = "no-cache"> <meta http-equiv = "cache-control"content = "no-cache"> <meta http-equiv = "meta http-equiv ="contain "> <meta http-equiv ="keyword1, keyword2, keyword2, keyword2. http-equiv = "description"content = "이것은 내 페이지입니다"> <!-<link rel = "stylesheet"type = "text/css"href = "styles.css">-> </head> <center> <h1 style = "green"> 로그인 </h1> <% request. 문자열 이름 = request.getParameter ( "name"); 문자열 pwd = request.getParameter ( "pwd"); %> 로그인 사용자 이름은 다음과 같습니다. < %= 이름 %> <br> 로그인의 비밀번호는 다음과 같습니다. < %= pwd %> </body> </body> </html>
이 기사가 모든 사람의 Java 프로그래밍에 도움이되기를 바랍니다.