JSP共有以下9种基本内置组件(可与ASP的6种内部组件相对应):
request 用户端请求,此请求会包含来自GET/POST请求的参数 response 网页传回用户端的回应 pageContext 网页的属性是在这里管理 session 与请求有关的会话期 application Servlet正在执行的内容 out 用来传送回应的输出 config Servlet的构架部件 page JSP网页本身 exception 针对错误网页,未捕捉的例外 |
q1.html
- <form action="q2.jsp" method="post">
- Your Name:<input type="text" name="username" />
- <input type="submit" value="Submit" />
- </form>
q2.jsp
- <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
- <html>
- <head>
- <title>My JSP 'q2.jsp' starting page</title>
- </head>
-
- <body>
- <%
- out.println("Welcome to our site, "+request.getParameter("username"));
- String name = (String)request.getParameter("username");
- session.putValue("name",name);
- session.setAttribute("randnum",new Random(22222));
-
- %>
- <hr/>
- <form action="q3.jsp" method="post">
- Your Hobby:<input type="text" name="hobby" />
- <input type="submit" value="jump to q3.jsp" />
- </form>
-
- </body>
- </html>
q3.jsp
- <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
- <html>
- <head>
- <title>My JSP 'q3.jsp' starting page</title>
- </head>
- <body>
- Here si q3.jsp<br/>
- Have a nice day, <u><%= session.getValue("name") %></u>
- <br/>
- Your hobby is/are:<u> <%= request.getParameter("hobby") %></u>
- <br/>
- The random NO. is: <%= session.getAttribute("randnum") %>
- </body>
- </html>
阅读(632) | 评论(0) | 转发(0) |