Đối tượng request trong JSP

Đối tượng request trong JSP

Đối tượng request trong JSP

Learn more »

Đối tượng request trong JSP



Đối tượng request trong JSP là một đối tượng ẩn của javax.servlet.http.HttpServletRequest. Mỗi lần client request một trang thì JSP engine tạo ra một đối tượng mới để đại diện cho request đó.

Đối tượng request cung cấp các phương thức để lấy thông tin HTTP header bao gồm Form data, cookie, HTTP method vv.

Nó có thể được sử dụng để get, set và remove các thuộc tính trong phạm vi jsp request.


Ví dụ về đối tượng request trong JSP

Tạo trang index.html

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Doi tuong reqest trong JSP</title> </head> <body>   <form action="welcome.jsp">     <input type="text" name="username">      <input type="submit" value="Submit"><br>   </form> </body> </html> 

Tạo trang welcome.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>Welcome page</title> </head> <body>   <%       String name = request.getParameter("username");       out.print("welcome " + name);   %> </body> </html> 

Kết quả:

Đối tượng request trong JSP

click Submit.

Đối tượng request trong JSP


Lượt xem : 316

Integrations
Users

Share Profile

Anyone at KeenThemes can view
Anyone with link can edit

Give Award

Anyone at KeenThemes can view
Anyone with link can edit

Report User

Let us know why you’re reporing this person
Don't worry, your report is completely anonymous; the person you're
reporting will not be informed that you've submitted it