JSP中的参数传递方法
(1)利用<jsp:param name="paramName" value="paramValue"></jsp:param>其中name为与属性相关联的关键词,value为属性的值。
示例:传常量字符串<param name="userName" value="shilei"/>
示例:传变量 User user=new User("shilei");//User是一个类
<jsp:param name="user" value="<%=user%>"/>//<%=user%>里面括起来的是jsp表达式
(2)利用session.setAttribute("attributeName",attribute)或者request.setAttribute("attributeName",attribute)
示例:User user=new User("shilei");
session.setAttribute("userName",user);
(3)就像传统的html那样利用表单专递参数。
示例:<form name="loginForm" action="checkLogin.jsp" method="get">
<input type="text" name="username">
<input type="password" name="userpwd">
<input type="submit" value="提交">
</form>
(4)直接挂在URL后面。示例:response.sendRedirect("checkLogin.jsp?username="+username+"&userpwd="+userpwd"");
String name=request.getParameter("name");
<a href="welcome.jsp?name=<%=name%>">
(5)利用cookie对象来传递
Cookie cookie=new Cookie("my","liuliu")
cookie.setMaxage(60*60);(以秒为单位)最大的生命周期
response.addCookie(cookie);
Cookie[] cookies=request.getCookies();(可以通过遍历此数组来访问值)
相关文档:
学习JSP主要学习他的9大对象(request, response, pageContext, session, application, out, config, page, exception ),这些对象都是静态对象,不用定义就可以直接使用,把他们都了解清楚并会运用,就可以在简历上添上一个熟悉技能:JSP
Jsp内置对象 功能 主要方法
out 向客户端输出数据 print() println() flush() ......
Jsp编码规范
1.1 文件后缀(File Suffixes)
文件类别 文件后缀
--------------------------------------
Java源文件 .java
Java字节码文件 .class
动态页面 .jsp
静态页面 .html
脚本文件 .js
1.2 常用文件名(Common ......
http:/localhost/123/jsp/test.jsp:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logi ......
我先说明一下配置环境的大概情况:
* FreeBSD 7.0-RELEASE
* apache-2.2.9
* mod_jk-ap2-1.2.26
* diablo-jdk-1.6.0.07.02
* tomcat-6.0.16
具体的版本信息显示如下:
freebsd# pkg_info
apache-2.2.9_5 Version 2.2.x of Apache web server&nbs ......
在项目中,我们经常遇到需要在jsp页面切换中传递中文字符。这主要有两种方式。
URL方式,例如:http://website/test1.jsp?act=add&type=苹果¶m=%20D%20B
FORM方式,例如:
<form name=test mehtod="post">
<input type=hidden name=text2 value="中文">
<input type=t ......