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ÎļþÖÐʹÓÃÕâЩ±êÇ©,ÕâÑù¿ÉÒÔʹjsp´úÂë¸ü¼ò½à!
Ê×ÏÈÕâÀïÏȽéÉÜ´Ó¶¨Òå±êÇ©µ½Ê¹ÓñêÇ©µÄ²½Öè:
1,´´½¨×Ô¶¨Òå±êÇ©´¦ÀíÀà,¼°Ïà¹ØÀà.class ²¢ÇÒ°ÑËûÃǶ¼·ÅÔÚWEB-INF/classesĿ¼ÏÂ
2,´´½¨TLD±êÇ©¿âÃèÊöÎļþ(.tld)Î ......
ÔÚ²»ÔÊÐíĿ¼ä¯ÀÀµÄÇé¿öÏ ä¯ÀÀÆ÷»áÏÈÕÒµ½Ê×Ò³£¨Ä¬ÈÏΪindex.html /index.jsp...£©
·ñÔò³ö´í
Òò´Ë ÈôÊ×Ò³±»¶ñÒâ¸ü¸Ä ÍøÕ¾±ÀÀ£
½â¾ö·½·¨£º
¸ü¸ÄĬÈÏÆô¶¯Ò³Ã棺$tomcat/conf/web.xml×îºóλÖÃ
<welcome-file-list>
<welcome-file>index.html</welcome-file> ......
ÎÒÏÈ˵Ã÷Ò»ÏÂÅäÖû·¾³µÄ´ó¸ÅÇé¿ö£º
* 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 ......
Servlet£º
ÔÚServletÖУ¬Ìø×ªÔÚdoGet»òÕßdoPost·½·¨ÖÐʵÏÖ¡£
<1>redirectʵÏÖÒ³ÃæÌø×ª£º
response.sendRedirect("/login.jsp");
·½·¨µÄ²ÎÊýÊÇÏà¶Ô·¾¶£¬É趨Õâ¸ö²ÎÊý¿ÉÒÔÊ¹Ò³ÃæÌø×ªµ½ÈκÎÒ³Ãæ£¬°üÀ¨www.baidu.comµÈÍøÂçÒ³Ãæ¡£
Ìø×ªºóÄã¿ÉÒÔ·¢ÏÖµØÖ·À¸·¢ÉúÁ˱仯¡£
µ×²ãÔÀí£ºÊ¹ÓÃredir ......
·pageContext£ºÌṩ¶ÔÒ³ÃæÊôÐԵķÃÎÊ¡£
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("basePath",basePath);
%>
ʹÓãº
${pageScope}
·reques ......