JSPÖеIJÎÊý´«µÝ·½·¨
£¨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ÖеÚÒ»¾ä£º
<%@ page language="java" import="java.sql.*,java.util.*," contentType="text/HTML;charset=gb2312" pageEncoding="gb2312"%>
htmlÖмÓÉÏ
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
ͨ³£ÕâÑù¾ÍûÓÐÎÊÌâÁË¡£ .
ÔÙÕߣº µ¼ÈëjsʱºòÉ ......
jspµÄpageEncoding="UTF-8",strutsµÄencoding="UTF-8"£¬eclipse µÄ¹¤×÷Çø¼äµÄ±àÂ뷽ʽÊÇGBK£¬µ«ÊÇÔÚstrutsµÄactionÖлñµÃµÄjsp´«À´µÄÖÐÎÄÖÐÓÐÂÒÂ룬ʹÓÃnew String(sysgkForm.getContent().getBytes("UTF-8"),"GBK")תÂëÒ²²»ÐУ¬×îºó·¢ÏÖÎÊÌâ³öÔÚÁËjspÀïÃæ¡£¼ÓÉÏcontentType="text/html; charset=GBK" ¾ÍºÃÁË¡£
pageEncodi ......
ÎÒÏÈ˵Ã÷Ò»ÏÂÅäÖû·¾³µÄ´ó¸ÅÇé¿ö£º
* 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 ......
·pageContext£ºÌṩ¶ÔÒ³ÃæÊôÐԵķÃÎÊ¡£
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("basePath",basePath);
%>
ʹÓãº
${pageScope}
·reques ......