璇烽棶杩欐浠g爜鏄粈涔堟剰鎬濓紵锛?/a>

时间:2022-05-08 21:13:58
杩欐槸涔︿笂鐨勪袱娈典唬鐮侊細

test_application.jsp

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>浣跨敤璁℃暟鍣ㄧ殑渚嬪瓙</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
娴嬭瘯application鐨勯〉闈€?lt;br>
<jsp:include page="application.jsp">
<jsp:param name="counter_name" value="test_application"/>
</jsp:include>
</body>
</html>

application.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"%> 
<%
int count=0;
String counter_name=request.getParameter("counter_name");
try
{
 count=Integer.parseInt((application.getAttribute(counter_name).toString()));
}
catch(Exception e)
{
  out.println("鏈夐敊璇紒锛?);
}
out.println("鑷粠搴旂敤鏈嶅姟鍣ㄥ惎鍔ㄥ悗锛屾椤甸潰宸茬粡璁块棶浜?+count+"娆?);
count++;
application.setAttribute(counter_name,new Integer(count));
%>

鍏朵腑
count=Integer.parseInt((application.getAttribute(counter_name).toString()));
鐫€鏉¤鍙ユ垜涓嶆槑鐧芥槸浠€涔堟剰鎬濓紝瀹冪殑浣滅敤鏄粈涔堬紵锛?
out.println("鏈夐敊璇紒锛?);杩欏彞鏄垜鑷繁鍔犱笂鍘荤殑 
鐜板湪杩愯鐨勭粨鏋滄槸锛氱涓€娆℃墦寮€缃戦〉鏈夆€滄湁閿欒鈥濇墦鍗板嚭鏉ワ紝浣嗕箣鍚庘€滃埛鏂扳€?nbsp;灏遍兘娌℃湁杩欏彞璇濇墦鍗板嚭鏉ヤ簡 鍏朵粬鐨勪篃姝e父锛侊紒 杩欐槸涓轰粈涔堝憿锛燂紵 涓嶅お鐞嗚В锛侊紒

7 涓В鍐虫柟妗?/h2>

#1


鍥犱负绗竴娆″姞杞借繖涓〉闈㈡椂((application.getAttribute(counter_name).toString()))寰楀埌鐨勫€兼槸涓猲ull锛屾墍浠nteger.parseInt((application.getAttribute(counter_name).toString()))浼氫骇鐢熶竴涓浆鎹㈠紓甯革紝鍗虫墽琛宱ut.println("鏈夐敊璇紒锛?);骞朵笖鎵ц鍚庨潰鐨勮鍙ヨ繖鏃禼ount鐨勫€兼槸1锛屽皢杩欎釜鍊煎寘瑁呮垚integer绫诲瀷锛屽瓨鍏pplication瀵硅薄銆?
   鍒扮浜屾鐨勬椂鍊欙紝 count=Integer.parseInt((application.getAttribute(counter_name).toString()))绛変环涓巆ount=Integer.parseInt((application.getAttribute(1).toString()))=1锛屽洜姝や笉浼氫骇鐢熻浆鎹㈠紓甯革紝杩愯姝e父銆?
濡傛灉涓ゆ閮芥甯哥殑璇濆簲璇ヨ繖鏍峰啓锛?
      if锛坅pplication.getAttribute(counter_name)==null)
      count=0
     else
      count=Integer.parseInt((application.getAttribute(counter_name).toString()));

#2


count=Integer.parseInt((application.getAttribute(counter_name).toString()));
count鏄痠nt褰㈠彉閲忥紝application.getAttribute(counter_name).toString()鏄粠application浼氳瘽涓彇鍑哄璞★紝瀹冩槸涓€涓瓧绗︿覆锛屽洜涓轰袱鑰呮暟鎹被鍨嬩笉鍚岋紝璧嬪€兼椂浣跨敤Integer.parseInt()鏂规硶鏉ヨ繘琛岀被鍨嬭浆鎹€?


out.println("鏈夐敊璇紒锛?);
绗竴娆℃墦寮€缃戦〉鐨勬椂鍊欏湪counter_name璧嬪€间负request.getParameter("counter_name")涓瓨鏀剧殑鍐呭锛岃€屽洜涓烘槸绗竴娆℃墦寮€锛岃繖涓璞′腑鐨勫唴瀹规槸绌虹殑锛屽嵆null锛屾墍浠pplication.getAttribute(counter_name)鐨勫€间篃鏄┖(null)锛屽綋涓€涓猲ull鍋歵oString()鐨勭被鍨嬭浆鎹㈠氨浼氭姏鍑哄紓甯革紝杈撳嚭鈥滄湁閿欒!鈥濄€傝€屼箣鍚庤繖鍙ヨ鍙?
application.setAttribute(counter_name,new Integer(count));
缁х画鍙堟妸杩欎釜鏈鏄┖鐨刟pplication瀵硅薄counter_name璁剧疆浜嗗€硷紝鎵€浠ョ浜屾鎵撳紑缃戦〉鐨勬椂鍊欒繘琛宼oString()绫诲瀷杞崲鏃跺氨涓嶄細鎶涘嚭寮傚父浜?

#3


鍦╟ount=Integer.parseInt((application.getAttribute(counter_name).toString()));涓?
Integer.parseInt()鏂规硶 涓轰粈涔堣涓ゅ眰鎷彿鍟婏紝杩欐牱缂栬瘧鏃舵€庝箞涓嶄細鎶ラ敊鍟婏紵锛?
杩樻湁灏辨槸姣忔鈥滃埛鏂扳€濈殑鏃跺€欙紝瀛楃涓?test_application"涓嶉兘浼氫紶閫掔粰String counter_name 鍚楋紵

#4


鍝綅鏈嬪弸鍐嶅府瑙g瓟涓€涓嬪晩锛侊紒锛燂紵

#5


澶氫竴灞傛嫭鍙峰彧鏄涓€娆′紭鍏堢骇杩愮畻锛岃娉曚笂骞舵病鏈夐敊
瀛楃涓?test_application"鐨勭‘閮戒細浼犻€掔粰String counter_name 锛屼絾涓嶄細浼犵粰application.getAttribute(counter_name)

#6


濂界殑  杩欐鏄庣櫧浜嗭紝  璋㈣阿浜嗭紒锛侊紒

#7


澶珮娣变簡鍟?鏈夋病鏈夌炕璇戝晩

#1


鍥犱负绗竴娆″姞杞借繖涓〉闈㈡椂((application.getAttribute(counter_name).toString()))寰楀埌鐨勫€兼槸涓猲ull锛屾墍浠nteger.parseInt((application.getAttribute(counter_name).toString()))浼氫骇鐢熶竴涓浆鎹㈠紓甯革紝鍗虫墽琛宱ut.println("鏈夐敊璇紒锛?);骞朵笖鎵ц鍚庨潰鐨勮鍙ヨ繖鏃禼ount鐨勫€兼槸1锛屽皢杩欎釜鍊煎寘瑁呮垚integer绫诲瀷锛屽瓨鍏pplication瀵硅薄銆?
   鍒扮浜屾鐨勬椂鍊欙紝 count=Integer.parseInt((application.getAttribute(counter_name).toString()))绛変环涓巆ount=Integer.parseInt((application.getAttribute(1).toString()))=1锛屽洜姝や笉浼氫骇鐢熻浆鎹㈠紓甯革紝杩愯姝e父銆?
濡傛灉涓ゆ閮芥甯哥殑璇濆簲璇ヨ繖鏍峰啓锛?
      if锛坅pplication.getAttribute(counter_name)==null)
      count=0
     else
      count=Integer.parseInt((application.getAttribute(counter_name).toString()));

#2


count=Integer.parseInt((application.getAttribute(counter_name).toString()));
count鏄痠nt褰㈠彉閲忥紝application.getAttribute(counter_name).toString()鏄粠application浼氳瘽涓彇鍑哄璞★紝瀹冩槸涓€涓瓧绗︿覆锛屽洜涓轰袱鑰呮暟鎹被鍨嬩笉鍚岋紝璧嬪€兼椂浣跨敤Integer.parseInt()鏂规硶鏉ヨ繘琛岀被鍨嬭浆鎹€?


out.println("鏈夐敊璇紒锛?);
绗竴娆℃墦寮€缃戦〉鐨勬椂鍊欏湪counter_name璧嬪€间负request.getParameter("counter_name")涓瓨鏀剧殑鍐呭锛岃€屽洜涓烘槸绗竴娆℃墦寮€锛岃繖涓璞′腑鐨勫唴瀹规槸绌虹殑锛屽嵆null锛屾墍浠pplication.getAttribute(counter_name)鐨勫€间篃鏄┖(null)锛屽綋涓€涓猲ull鍋歵oString()鐨勭被鍨嬭浆鎹㈠氨浼氭姏鍑哄紓甯革紝杈撳嚭鈥滄湁閿欒!鈥濄€傝€屼箣鍚庤繖鍙ヨ鍙?
application.setAttribute(counter_name,new Integer(count));
缁х画鍙堟妸杩欎釜鏈鏄┖鐨刟pplication瀵硅薄counter_name璁剧疆浜嗗€硷紝鎵€浠ョ浜屾鎵撳紑缃戦〉鐨勬椂鍊欒繘琛宼oString()绫诲瀷杞崲鏃跺氨涓嶄細鎶涘嚭寮傚父浜?

#3


鍦╟ount=Integer.parseInt((application.getAttribute(counter_name).toString()));涓?
Integer.parseInt()鏂规硶 涓轰粈涔堣涓ゅ眰鎷彿鍟婏紝杩欐牱缂栬瘧鏃舵€庝箞涓嶄細鎶ラ敊鍟婏紵锛?
杩樻湁灏辨槸姣忔鈥滃埛鏂扳€濈殑鏃跺€欙紝瀛楃涓?test_application"涓嶉兘浼氫紶閫掔粰String counter_name 鍚楋紵

#4


鍝綅鏈嬪弸鍐嶅府瑙g瓟涓€涓嬪晩锛侊紒锛燂紵

#5


澶氫竴灞傛嫭鍙峰彧鏄涓€娆′紭鍏堢骇杩愮畻锛岃娉曚笂骞舵病鏈夐敊
瀛楃涓?test_application"鐨勭‘閮戒細浼犻€掔粰String counter_name 锛屼絾涓嶄細浼犵粰application.getAttribute(counter_name)

#6


濂界殑  杩欐鏄庣櫧浜嗭紝  璋㈣阿浜嗭紒锛侊紒

#7


澶珮娣变簡鍟?鏈夋病鏈夌炕璇戝晩