显示两个按钮分别测试
jsp页面
<span class="vbscript"><%-- Created by IntelliJ IDEA. User: brian <span class="hljs-built_in">Date</span>: <span class="hljs-number">2016</span>/<span class="hljs-number">3</span>/<span class="hljs-number">7</span> <span class="hljs-built_in">Time</span>: <span class="hljs-number">20</span>:<span class="hljs-number">49</span> <span class="hljs-keyword">To</span> change this template use File | Settings | File Templates. --%></span> <span class="vbscript"><%@ page contentType=<span class="hljs-string">"text/html;charset=UTF-8"</span> language=<span class="hljs-string">"java"</span> %></span> <span class="hljs-tag"><<span class="hljs-title">html</span>></span> <span class="hljs-tag"><<span class="hljs-title">head</span>></span>
<span class="hljs-tag"><<span class="hljs-title">meta</span> <span class="hljs-attribute">http-equiv</span>=<span class="hljs-value">"Content-Type"</span> <span class="hljs-attribute">content</span>=<span class="hljs-value">"text/html; charset=UTF-8"</span>></span>
<span class="hljs-tag"><<span class="hljs-title">title</span>></span>json交互测试<span class="hljs-tag"></<span class="hljs-title">title</span>></span>
<span class="hljs-tag"><<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"text/javascript"</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">"${pageContext.request.contextPath }/js/jquery-1.4.4.min.js"</span>></span><span class="javascript"></span><span class="hljs-tag"></<span class="hljs-title">script</span>></span>
<span class="hljs-tag"><<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"text/javascript"</span>></span><span class="javascript">
<span class="hljs-comment">//请求json,输出是json</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">requestJson</span><span class="hljs-params">()</span>{</span>
省略 }
<span class="hljs-comment">//请求key/value,输出是json</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">responseJson</span><span class="hljs-params">()</span>{</span> 省略 }
</span><span class="hljs-tag"></<span class="hljs-title">script</span>></span> <span class="hljs-tag"></<span class="hljs-title">head</span>></span> <span class="hljs-tag"><<span class="hljs-title">body</span>></span> <span class="hljs-tag"><<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"button"</span> <span class="hljs-attribute">onclick</span>=<span class="hljs-value">"requestJson()"</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"请求json,输出是json"</span>/></span> <span class="hljs-tag"><<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"button"</span> <span class="hljs-attribute">onclick</span>=<span class="hljs-value">"responseJson()"</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"请求key/value,输出是json"</span>/></span> <span class="hljs-tag"></<span class="hljs-title">body</span>></span>
controller
<span class="hljs-annotation">@Controller</span> <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">JsonTest</span> {</span>
省略 }
测试结果
输入json串,输出是json串