java,在controller中传值给jsp页面 spring中controller向jsp页面传值
\u600e\u4e48\u628ajava\u4ece\u540e\u53f0\u53d6\u5230\u7684\u6570\u636e\u4f20\u5230jsp\u9875\u9762\u53c2\u8003\u4e0b\u9762
\u6bd4\u5982\u5728\u540e\u53f0\u8bbe\u7f6e\u4e00\u4e2a\u503c\u5728request\u91cc\u9762\uff0crequest.setAttribute("param",param);
\u5728jsp\u9875\u9762\u5c31\u53ef\u4ee5\u8fd9\u6837\u83b7\u53d6\uff0c${param}; el\u8868\u8fbe\u5f0f\u3002
\u5728\u9875\u9762\u4f20\u503c\u5230\u540e\u53f0\u4e2d\uff0c\u7b2c\u4e00\u79cdpost\u65b9\u5f0f\uff0c\u63d0\u4ea4\u8868\u5355\u65f6\u3002
\u70b9\u51fb\u63d0\u4ea4\u6309\u94ae\u540e\u5728\u540e\u53f0\u83b7\u53d6Username,\u548cpassword
String username =request.getParamter("username");
String password=request.getParamter("password");
\u5982\u679c\u662fget\u65b9\u5f0f\u63d0\u4ea4\u7684\u8bdd
\u4e3e\u4e2a\u4f8b\u5b50\uff1a
\u67e5\u770b
\u90a3\u4e48\u5728\u540e\u5728\u83b7\u53d6\u4e5f\u662f\u4e00\u6837\u7684
String param1=request.getParamter("param1");
\u5bf9printwelcome\u52a0\u4e0a@ResponseBody\uff0crequestmapping\u91cc\u4e5f\u8981\u7ed9\u4e2a\u5730\u5740\uff0c\u4e4b\u540e\u8fd4\u56de\u503c\u7528Modelmap\uff0c\u4e5f\u5c31\u662fretrun model
\u524d\u53f0\u7528ajax\u53d1\u9001\u8bf7\u6c42\uff0c\u7136\u540e\u7528data.message\u5c31\u53d6\u5230\u4e86\u201cspring3 MVC \u4f8b\u5b50\u201d\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e86
绛旓細1. java.lang.nullpointerexception 杩欎釜寮傚父澶у鑲畾閮界粡甯搁亣鍒帮紝寮傚父鐨勮В閲婃槸"绋嬪簭閬囦笂浜嗙┖鎸囬拡"锛岀畝鍗曞湴璇村氨鏄皟鐢ㄤ簡鏈粡鍒濆鍖栫殑瀵硅薄鎴栬呮槸涓嶅瓨鍦ㄧ殑瀵硅薄锛岃繖涓敊璇粡甯稿嚭鐜板湪鍒涘缓鍥剧墖锛岃皟鐢ㄦ暟缁勮繖浜涙搷浣滀腑锛屾瘮濡傚浘鐗囨湭缁忓垵濮嬪寲锛屾垨鑰呭浘鐗囧垱寤烘椂鐨勮矾寰勯敊璇瓑绛夈傚鏁扮粍鎿嶄綔涓嚭鐜扮┖鎸囬拡锛屽緢澶氭儏鍐典笅鏄竴浜...
绛旓細濡傛灉娌℃湁鐢ㄦ鏋剁殑璇 灏卞皢椤甸潰涓婄殑value缁戝畾鍒皉equest涓婇潰鍦╯ervlet涓幏鍙栵紝濡傛灉鏄controller鍚慾sp浼犲弬涔熶竴鏍锋垨鑰卻ession
绛旓細鑳藉啓鍦controller灞傜殑楠岃瘉锛堝嵆鏃犻渶璋冪敤dao灞備唬鐮侊級閮藉啓鍦╟ontroller锛堝洜涓哄疄闄呬笂浣犲湪ui宸茬粡鍐欒繃浜嗭紝姝ゆ椂浣犲畬鍏ㄦ病蹇呰鍐嶆妸瀹冨綋鎴愪竴涓滀笟鍔♀濇潵瀵瑰緟锛夛紝涓嶈兘鐨勶紝鍐欏湪service灞傦紙浣嗘槸鏈濂芥槸浣滀负涓涓嫭绔嬬殑鏂规硶瀛樺湪锛岃屼笉鏄斁鍦╯ervice鐨勪笟鍔℃柟娉曢噷浣滀负涓娈典唬鐮佸瓨鍦級...
绛旓細Controller涓鑸寚鐨勬槸MVC鏋舵瀯閲岀殑鎺у埗灞傦紝鏄椤圭洰閲岀殑鍔熻兘鍋氱粺涓鐨勮皟搴︺java閲岀殑钁楀悕鐨凪VC妗嗘灦鏈塻truts鍜宻pringmvc銆備笉杩囪繖2涓兘鏄痡avaweb閲岀殑妗嗘灦鎶鏈
绛旓細SpringMVC鏄熀浜嶮VC鏋舵瀯鐨勬鏋讹紝涓嶄簡瑙g殑鍚屽闇鑷鐮旂┒鐩稿叧璧勬枡銆傛帴涓嬫潵锛屾垜浠皢鍦ㄥ凡鏈夌殑鐭ヨ瘑鍩虹涓婏紝寮鍙戝苟杩愯绗竴涓Controller銆傞鍏堬紝浠巗pring-framework-4.3.8.RELEASE-dist寮濮嬶紝涓嬭浇Spring-Framework鐨勪簩杩涘埗鐗堟湰锛屽悓鏃惰幏鍙朅pache鍑哄搧鐨刢ommon-logging-1.2搴撱傝В鍘嬪悗锛屽皢jar鍖呭姞鍏DEA鐨勪緷璧栬矾寰勶紝闈...
绛旓細鍙互鐩存帴鍦ㄨ繑鍥炵殑鏂规硶涓婃坊鍔燖ResponseBody 瀹炵幇瀵硅薄鑷姩杞崲json鏍煎紡 RequestMapping(value = "/get") @ResponseBodypublic Object getJson() { Map<String, Object> map = new HashMap(); map.put("name", "dhweicheng"); map.put("age", 25); return map;} ...
绛旓細org.springframework.web.servlet.mvc.Controller 鎺ュ彛銆備竴鑸儏鍐典笅锛屾垜浠槸閫氳繃缁ф壙 SimpleFormController 鎴 MultiActionController 鏉ュ畾涔夎嚜宸辩殑 Controller 鐨勩傚湪瀹氫箟 Controller 鍚庯紝涓涓噸瑕佺殑浜嬩欢鏄湪 Spring MVC 鐨勯厤缃枃浠朵腑閫氳繃 HandlerMapping 瀹氫箟璇锋眰鍜屾帶鍒跺櫒鐨勬槧灏勫叧绯伙紝浠ヤ究灏嗕袱鑰呭叧鑱旇捣鏉ャ傝缁嗙殑...
绛旓細Controller鏄礋璐e拰鍓嶇閫氫俊鐨勯儴鍒嗭紝灞炰簬mvc涓殑V灞锛屽湪鏀规垚鏈夊紑鏀剧粰澶栭儴鐨勬帴鍙o紝鎵鏈夌殑鏂规硶璋冪敤閮藉繀椤荤粡杩嘋ontroller灞傘傝繖鏍风殑濂藉鏄紝濡傛灉鎴戜滑瑕佸仛鎷︽埅鎴栬呮槸鏍¢獙锛屽彧闇瑕鍦–ontroller灞傚仛灏卞彲浠ョ殑
绛旓細Java鎶妔ql鍜宻ervice灞傜殑鏁版嵁閮藉啓鍦╟ontroller灞傚嵄瀹 涔嬪墠璁や负鎶奷ao灞傚拰service閫昏緫灞傚啓鍦╟ontroller鍙細鐪嬭捣鏉ュ緢涔,鍙兘浼氬奖鍝嶆晥鐜囥
绛旓細鎮ㄥソ锛岀湅鍒版偍鍥剧墖鐨勭洰褰曠粨鏋勶紝椤圭洰搴旇鏄熀浜 MVC 鐨勫垎灞傜粨鏋勮繘琛屽紑鍙戜唬鐮佺殑銆備竴鑸▼搴忕殑璇锋眰鍏ュ彛鏄偍鐨 controller 鍖呬笅闈傚鏋滅洰鍓嶈繕涓嶇‘瀹氭槸鍝釜璇锋眰锛屽厛鍦ㄦ祻瑙堝櫒鎵撳紑寮鍙戣呮帶鍒跺彴锛屾壘鍒板叿浣撶殑璇锋眰鍦板潃銆傝繖閲屼互浜笢涓轰緥銆傚煙鍚嶅悗闈㈢殑涓鑸氨鏄姹傜殑璺緞锛屾瘮濡備笅鍥捐繖涓 /getinfo銆傜‘璁ゅ叿浣撶殑璇锋眰璺緞鍚庯紝...