<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Using Protototype AJAX &amp; JSON with J2EE and Struts</title>
	<atom:link href="http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/</link>
	<description>A discourse on programming</description>
	<lastBuildDate>Wed, 01 Feb 2012 11:21:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: Anjib</title>
		<link>http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/comment-page-1/#comment-77477</link>
		<dc:creator>Anjib</dc:creator>
		<pubDate>Mon, 17 Oct 2011 16:58:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/#comment-77477</guid>
		<description>Seems JSP and struts-config.xml page codes are not showing properly
JSP Page
-----------
&lt;%-- 



    
        
        JSP Page
        
        
        
            function lookup() {
                new Ajax.Request(&#039;namelookup.do&#039;, {
                    parameters: {theId: $(&#039;theId&#039;).value},
                    onSuccess: function(transport, json) {
                        if(json.executeError) {
                            alert(json.executeError);
                        }
                        else {
                            $(&#039;fullName&#039;).value = json.fullName;
                        }   
                    }
                });
            }
        
    
    
        Hello World!
        
        
    

--%&gt;

struts-config.xml
---------------------
&lt;!--  --&gt;</description>
		<content:encoded><![CDATA[<p>Seems JSP and struts-config.xml page codes are not showing properly<br />
JSP Page<br />
&#8212;&#8212;&#8212;&#8211;<br />
&lt;%&#8211; </p>
<p>        JSP Page</p>
<p>            function lookup() {<br />
                new Ajax.Request(&#8216;namelookup.do&#8217;, {<br />
                    parameters: {theId: $(&#8216;theId&#8217;).value},<br />
                    onSuccess: function(transport, json) {<br />
                        if(json.executeError) {<br />
                            alert(json.executeError);<br />
                        }<br />
                        else {<br />
                            $(&#8216;fullName&#8217;).value = json.fullName;<br />
                        }<br />
                    }<br />
                });<br />
            }</p>
<p>        Hello World!</p>
<p>&#8211;%&gt;</p>
<p>struts-config.xml<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&lt;!&#8211;  &#8211;&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anjib</title>
		<link>http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/comment-page-1/#comment-77464</link>
		<dc:creator>Anjib</dc:creator>
		<pubDate>Mon, 17 Oct 2011 14:42:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/#comment-77464</guid>
		<description>Complete code

JSP Page
-----------



    
        
        JSP Page
        
        
        
            function lookup() {
                new Ajax.Request(&#039;namelookup.do&#039;, {
                    parameters: {theId: $(&#039;theId&#039;).value},
                    onSuccess: function(transport, json) {
                        if(json.executeError) {
                            alert(json.executeError);
                        }
                        else {
                            $(&#039;fullName&#039;).value = json.fullName;
                        }   
                    }
                });
            }
        
    
    
        Hello World!
        
        
    


Action Class
----------------
public class NameLookupAction extends org.apache.struts.action.Action {

    /* forward name=&quot;success&quot; path=&quot;&quot; */
    private static final String SUCCESS = &quot;success&quot;;

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        String theId = request.getParameter(&quot;theId&quot;);

        try {

            //Do your database work here to grab the name and populate our HashMap hm
            //In this example I&#039;ll just hard-code the name though.

            HashMap hm = new HashMap();
            hm.put(&quot;fullName&quot;, &quot;Joe Blow&quot;);

            //each key from our hash map becomes a key in our JSON object
            JSONObject json = JSONObject.fromObject(hm);

            //Plop it in the header so prototype can grab it.
            response.setHeader(&quot;X-JSON&quot;, json.toString());

        } catch (Exception e) {
            HashMap hm = new HashMap();
            hm.put(&quot;executeError&quot;, &quot;Couldn&#039;t find the Full Name because an error occured.&quot;);

            JSONObject json = JSONObject.fromObject(hm);

            response.setHeader(&quot;X-JSON&quot;, json.toString());

        }


        return null;
    }
}

struts-config.xml
----------------------
</description>
		<content:encoded><![CDATA[<p>Complete code</p>
<p>JSP Page<br />
&#8212;&#8212;&#8212;&#8211;</p>
<p>        JSP Page</p>
<p>            function lookup() {<br />
                new Ajax.Request(&#8216;namelookup.do&#8217;, {<br />
                    parameters: {theId: $(&#8216;theId&#8217;).value},<br />
                    onSuccess: function(transport, json) {<br />
                        if(json.executeError) {<br />
                            alert(json.executeError);<br />
                        }<br />
                        else {<br />
                            $(&#8216;fullName&#8217;).value = json.fullName;<br />
                        }<br />
                    }<br />
                });<br />
            }</p>
<p>        Hello World!</p>
<p>Action Class<br />
&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
public class NameLookupAction extends org.apache.struts.action.Action {</p>
<p>    /* forward name=&#8221;success&#8221; path=&#8221;" */<br />
    private static final String SUCCESS = &#8220;success&#8221;;</p>
<p>    /**<br />
     * This is the action called from the Struts framework.<br />
     * @param mapping The ActionMapping used to select this instance.<br />
     * @param form The optional ActionForm bean for this request.<br />
     * @param request The HTTP Request we are processing.<br />
     * @param response The HTTP Response we are processing.<br />
     * @throws java.lang.Exception<br />
     * @return<br />
     */<br />
    @Override<br />
    public ActionForward execute(ActionMapping mapping, ActionForm form,<br />
            HttpServletRequest request, HttpServletResponse response)<br />
            throws Exception {</p>
<p>        String theId = request.getParameter(&#8220;theId&#8221;);</p>
<p>        try {</p>
<p>            //Do your database work here to grab the name and populate our HashMap hm<br />
            //In this example I&#8217;ll just hard-code the name though.</p>
<p>            HashMap hm = new HashMap();<br />
            hm.put(&#8220;fullName&#8221;, &#8220;Joe Blow&#8221;);</p>
<p>            //each key from our hash map becomes a key in our JSON object<br />
            JSONObject json = JSONObject.fromObject(hm);</p>
<p>            //Plop it in the header so prototype can grab it.<br />
            response.setHeader(&#8220;X-JSON&#8221;, json.toString());</p>
<p>        } catch (Exception e) {<br />
            HashMap hm = new HashMap();<br />
            hm.put(&#8220;executeError&#8221;, &#8220;Couldn&#8217;t find the Full Name because an error occured.&#8221;);</p>
<p>            JSONObject json = JSONObject.fromObject(hm);</p>
<p>            response.setHeader(&#8220;X-JSON&#8221;, json.toString());</p>
<p>        }</p>
<p>        return null;<br />
    }<br />
}</p>
<p>struts-config.xml<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kamal</title>
		<link>http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/comment-page-1/#comment-54092</link>
		<dc:creator>Kamal</dc:creator>
		<pubDate>Sat, 16 Apr 2011 16:11:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/#comment-54092</guid>
		<description>Hi,

can you please put a complete code, I would like to try it, run it .
thanks</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>can you please put a complete code, I would like to try it, run it .<br />
thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: japan tsunami</title>
		<link>http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/comment-page-1/#comment-49810</link>
		<dc:creator>japan tsunami</dc:creator>
		<pubDate>Mon, 14 Mar 2011 16:42:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/#comment-49810</guid>
		<description>Help support the great nation of Japan from the earthquake by performing a small donation!</description>
		<content:encoded><![CDATA[<p>Help support the great nation of Japan from the earthquake by performing a small donation!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: seyhan basmacı</title>
		<link>http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/comment-page-1/#comment-30436</link>
		<dc:creator>seyhan basmacı</dc:creator>
		<pubDate>Wed, 03 Mar 2010 08:13:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/#comment-30436</guid>
		<description>for the last statement (return mapping.findForward(&quot;success&quot;);)  , you can just return null to inform struts about response already sent to client. 

return null;

no need for empty.jsp and struts-config.xml definition.</description>
		<content:encoded><![CDATA[<p>for the last statement (return mapping.findForward(&#8220;success&#8221;);)  , you can just return null to inform struts about response already sent to client. </p>
<p>return null;</p>
<p>no need for empty.jsp and struts-config.xml definition.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deepali</title>
		<link>http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/comment-page-1/#comment-5762</link>
		<dc:creator>Deepali</dc:creator>
		<pubDate>Mon, 28 Jan 2008 10:32:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/#comment-5762</guid>
		<description>Hi,

It will be nice if there are more exapmles on JSON.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>It will be nice if there are more exapmles on JSON.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sachin</title>
		<link>http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/comment-page-1/#comment-5341</link>
		<dc:creator>Sachin</dc:creator>
		<pubDate>Fri, 21 Sep 2007 05:56:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.weheartcode.com/2007/05/16/using-protototype-ajax-json-with-j2ee-and-struts/#comment-5341</guid>
		<description>Nice tutorial. Thanks very much.
I wonder if there are more such examples that show the use of JSON with J2EE components</description>
		<content:encoded><![CDATA[<p>Nice tutorial. Thanks very much.<br />
I wonder if there are more such examples that show the use of JSON with J2EE components</p>
]]></content:encoded>
	</item>
</channel>
</rss>

