jsp useBean scopeÊôÐÔµÄÇø·Ö
scopeÊôÐÔÓÃÓÚÖ¸¶¨JavaBeanʵÀý¶ÔÏóËù´æ´¢µÄÓò·¶Î§£¬ÆäÈ¡ÖµÖ»ÄÜÊÇpage¡¢request¡¢sessionºÍapplicationËĸöÖµÖеÄÒ»¸ö£¬ÆäĬÈÏÖµÊÇpage¡£
ÎÒ¿ÉÒÔ²âÊÔÏÂÃæ´úÂ룺
date.jsp
---------------------------------------------------------
<jsp:useBean id="currentDate" class="java.util.Date" scope="request" />
<%=currentDate.toString() %>
²âÊÔ½á¹û£º
1¡¢µ±scope=applicationʱ£¬ÎÒÃÇä¯ÀÀdate.jsp£¬ÕâʱÏÔʾ³öÁËϵͳʱ¼ä¡£¿ÉÊDz»¹ÜÎÒÃÇÔõôˢУ¬ÁíÍâ´ò¿ªÒ»¸öä¯ÀÀÆ÷£¬ÉõÖÁ»»Ì¨»ú Æ÷£¬ËüÏÔʾµÄʱ¼äʼÖÕ²»±ä£¬¶¼Êǵ±³õµÄʱ¼ä(¼´bean¸Õ´´½¨Ê±µÃµ½µÄϵͳʱ¼ä)£¬ÒòΪscope=application£¬ËùÒÔJavaBeanµÄʵÀýÔÚÄÚ´æÖÐÖ»ÓÐÒ»·Ý£¬´ËʱֻҪ²»ÖØÐÂÆô¶¯WEB·þÎñ£¬Êä³ö²»»á±ä»¯¡£
2¡¢µ±scope=sessionʱ£¬ä¯ÀÀdate.jsp£¬Ë¢ÐÂʱÏÔʾҲ²»»á±ä»¯¡£¿ÉÊǵ±ÎÒÃÇÖØдò¿ªÒ»ä¯ÀÀÆ÷£¬¼´Ò»¸öеÄsession£¬ÏµÍ³±ãÔٴδ´½¨JavaBeanµÄʵÀý£¬È¡µÃµ±Ç°ÏµÍ³Ê±¼ä£¬Õâʱ½«µÃµ½ÕýÈ·µÄʱ¼ä¡£Í¬Ñù£¬ÔÙ´ÎË¢ÐÂдò¿ªµÄÒ³Ã棬ÏÔʾҲ²»»á±ä»¯¡£
3¡¢µ±scope=page/requestʱ£¬²»¶ÏË¢ÐÂÒ³Ã潫²»¶ÏµÃµ½µ±Ç°ÏµÍ³Ê±¼ä¡£
scopeÊôÐԵĸ÷¸öÉèÖÃÖµµÄÒâÒåºÍ×÷Óãº
£¨1£©page±íʾ½«JavaBeanʵÀý¶ÔÏó´æ´¢ÔÚPageContext¶ÔÏóÖУ¬×÷Ó÷¶Î§Êǵ±Ç°JSPÒ³ÃæÓÐЧ¡£
£¨2£©request±íʾ½«JavaBeanʵÀý¶ÔÏó´æ´¢ÔÚServletRequest¶ÔÏóÖУ¬´æ´¢ÔÚrequest¶ÔÏóÖеÄJavaBean¶ÔÏó¿ÉÒÔ±»ÊôÓÚͬһ¸öÇëÇóµÄËùÓÐServletºÍJSPÒ³Ãæ·ÃÎÊ¡£
£¨3£©session±íʾ½«JavaBeanʵÀý¶ÔÏó´æ´¢ÔÚHttpSession¶ÔÏóÖУ¬´æ´¢ÔÚHttpSession¶ÔÏóÖеÄJavaBean¶ÔÏó¿ÉÒÔ±»ÊôÓÚͬһ¸ö»á»°µÄËùÓÐServletºÍJSPÒ³Ãæ·ÃÎÊ£¬´ËÉèÖÃÒªÇóµ±Ç°JSPÒ³ÃæÖ§³ÖSession£¬¼´Ã»Óн«pageÖ¸ÁîµÄsessionÊôÐÔÉèÖÃΪfalse¡£Ò²¾ÍÊǶÔÒ»¸öÌض¨Óû§ÓÐЧ£¬Ò»¸öhttp»á»°¡£
£¨4£©application±íʾ½«JavaBeanʵÀý¶ÔÏó´æ´¢ÔÚServletContext¶ÔÏóÖУ¬´æ´¢ÔÚServletContext¶ÔÏóÖеÄJavaBean¶ÔÏó¿ÉÒÔ±»Í¬Ò»¸öWebÓ¦ÓóÌÐòÖеÄËùÓÐServletºÍJSPÒ³Ãæ·ÃÎÊ¡£Ò²¾ÍÊÇËùÓÐÓû§¶¼¿ÉÒÔʹÓá£
Ïà¹ØÎĵµ£º
<%@page import="com.opensymphony.xwork2.util.ValueStack"%><%
ValueStack vs = (ValueStack)request.getAttribute("struts.valueStack");
String aa = (String)vs.findValue("downloadContent");
response. ......
tomcat ĬÈÏʹÓõÄ×Ö·û¼¯ÊÇISO-8859-1£¬²»Ö§³ÖÖÐÎÄ×Ö·û£¬ËùÒÔÔÚÏÖʵÖÐÎÄʱÐèҪת»»×Ö·ûºÍÉèÖÃ×Ö·û¼¯¡£
server.mxl¸ÄΪ<Connector port="8080" protocol="HTTP/1.1" maxThreads="150" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" /> £¬Ìí¼Ó´úÂëת»»×Ö·ûString.getBytes("ISO-8859-1"),"UTF-8 ......
µ±ÔÚJSPµÄpageÖ¸ÁîÖÐÉèÖÃerrorPage="url"¾Í¿ÉÒÔÉèÖô¦ÀíÒ쳣ʼþµÄJSPÎļþ¡£Èç¿ÉÒÔÕâÑùд£º
<%@ page errorPage="error.jsp" %>
ÕâÑùµÄ»°£¬µ±Ò³ÃæÖгöÏÖÒì³£µÄÊ ......
JS´úÂë
<script
type="text/javascript">
function closewindow(){
window.returnValue = true;
window.close();
}
function clock(){
i = i -1;
if(document.getElementById("info")){
document.getElementById("info").innerHTML
......
JSPÖнá¹û¼¯ÏÔʾÈçÏ£º
<
ww:iterator
value
=
"resultList"
status
=
"status"
>
<
tr
class
=
"<ww:if test="
#status.even"
>
row-even
</
ww:if
> ......