struts2 + jquery + json ½øÐÐajaxÇëÇó
ÏîÄ¿ÖÐÏëÓÃajax£¬ÓÚÊÇÔÚÍøÉÏ°ÇÁËn¶à×ÊÁÏ£¬·¸ÁËn¶à´íÎ󣬴ӽñÌìÉϰൽÏÖÔÚÒ»Ö±ÔÚ´¦ÀíÕâ¸öÎÊÌ⣬ÖÕÓÚ»¹ÊÇ°ÑËü½â¾öÁË¡£
µ±ÎÒ¿´µ½Ò³ÃæµÄajaxÏÔʾºó£¬ÎÒÐË·ÜÒì³££¬ÎªÁ˼Ǽ×Ô¼ºÑ§Ï°µÄajaxÀú³Ì£¬Ò²ÎªÁËÈøü¶àµÄÈËÉÙ×ßÍä·£¬ÌØд´ËÒ»ÎÄÒÔ¼ÇÖ®£¡
·Ï»°²»ËµÁË£¬ÎªÁ˸üºÃµÄÀí½â£¬ÎÒÖØ×öÁËÒ»¸öСµÄÏîÄ¿£¬ÒÔ¼ÓÉîÓ¡Ïó¡£ÏÖÔÚ¾ÍÒÔÕâ¸öСÏîÄ¿¿ªÊ¼ÎÒÃǵÄajaxÖ®Âá£
µÚÒ»²½£º´´½¨ ÃûΪ"ajax" µÄ Java WebÏîÄ¿¡£
µÚ¶þ²½£º¼ÓÈëstruts2µÄjar°ü£¬ÕâÀïÐèÒªËĸö°ü freemarker.jar ognl.jar struts2-core.jar commons-fileupload.jar commons-io.jar xwork-core-2.1.6.jar£¨Õâ¸ö°ü¼ÓÉÏ°æ±¾ºÅ£¬ÊÇÒòΪÏÂÎÄÒªÌáµ½Ëü£©£¬ÕâÁù¸ö°üÊÇstruts±ØÐëÒÀÀµµÄjar°ü£¬Ê²Ã´ºÃ˵µÄ¡£
µÚÈý²½£ºÐÞ¸Ä web.xml ¼ÓÈë strutsµÄ¹ýÂËÆ÷£¬´úÂëÈçÏ£º
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
Ïà¹ØÎĵµ£º
ÍøÒ³ÖгöÏÖ“'sys' 䶨Òå
”»ò“'Sys' is undefined”µÄ´íÎó¡£
´ËʱÎÒÃÇÒª×öµÄÊÇÔÚ web.config
ÖÐ <system.web> Ò»½ÚÏÂÃæÌí¼ÓÀàËÆ
ÈçÏÂÄÚÈÝ£º
<httpHandlers>
<add
verb="GET,HEAD" path="ScriptResource.a ......
AjaxÈ«³ÆΪ“Asynchronous JavaScript and XML”£¨Òì²½JavaScriptºÍXML£©£¬ÊÇÒ»ÖÖ´´½¨½»»¥Ê½ÍøÒ³Ó¦ÓõÄÍøÒ³¿ª·¢¼¼Êõ¡£¸ù¾ÝAjaxÌá³öÕßJesse James Garrett½¨Ò飬Ëü£º
ʹÓÃXHTML+CSSÀ´±íʾÐÅÏ¢£»
ʹÓÃJavaScript²Ù×÷DOM£¨Document Object Model£©½øÐж¯Ì¬ÏÔʾ¼°½»»¥£»
ʹÓÃXMLºÍXSLT½øÐÐÊý¾Ý½»»»¼°Ïà¹Ø²Ù×÷£»
Ê ......
AJAX±íµ¥Ìá½»·½·¨£¨JSON£©
1./*****JAVA**************************************************************/
JAVAÀàÖУº
/*****JAVA**************************************************************/
2./*****struts.xml**************************************************************/
struts.xmlÎļþÖУº
......
1.´´½¨XMLHttpRequest¶ÔÏó£º
function newXMLHttpRequest() {
var requestObj;
if (window.XMLHttpRequest) {
// Non IE
requestObj = new ActiveObj('XMLHttpRequest');
} else {
//IE
requestObj = new ActiveObj('Microsoft.XMLHTTP');
}
return request ......
¡¡¡¡ºÜ¶àÈ˶¼ÓùýAJAX¿Ø¼þ°É£¬AJAX¿Ø¼þ²»ÐèҪˢÐÂÒ³Ãæ¾Í¿ÉÒÔµ½ºǫ́ȥ¶Á³öÊý¾Ýµ½¿Í»§¶Ë£®AJAX¿Ø¼þ³ýÁËÓкÜìŵÄÌØЧÍ⣬ÆäÒª¹¦ÄܾÍÊDz»ÐèҪˢÐÂÕû¸öÒ³Ãæ¾Í¿ÉÒÔÈ¡µÃÓû§ËùÐèÒªµÄÊý¾Ý£¬ÎÒ°ÑÕâÒ»¿éµÄµÄ¹¦ÄÜ·â×°³ÉÒ»¸öÀ࣬·½±ãÈÕºó¿ÉÒÔÖظ´Ê¹Ó㬴úÂëÈçÏ£º
//Ajax Request Class Start
functio ......