标签:
在我的理解,jsp就是那种可以把本来写在servlet的代码中的java代码写在了html里面。
jsp内置对象
1 request:
index.jsp,点击该页面的链接,进入deal.jsp。后者通过request接收前者传来的id,和user。
<%@ page language="java" import="java.util.*" pageEncoding="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> <base href="<%=basePath%>"> <title>My JSP ‘index.jsp‘ starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <a href="deal.jsp?id=1&user="sds">处理页</a> </body> </html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String id = request.getParameter("id"); //获取id参数的值 String user = request.getParameter("user"); //获取user参数的值 String pwd = request.getParameter("pwd"); //获取pwd参数的值 %> <% 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> <base href="<%=basePath%>"> <title>deal</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> id的参数为:<%=id %><br> user参数的值为:<%=user %><br> pwd参数的值为:<%=pwd %> </body> </html>
标签:
原文地址:http://www.cnblogs.com/rixiang/p/4732267.html