我已经阅读了很多关于这个主题的内容并且知道它应该如何工作,但无论如何我没有成功运行代码。
下面显示的代码正在运行但不加载JSONObject
。
这是我的x.jsp
:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="/struts-dojo-tags" prefix="sx"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<sx:head />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Auto complete example</title>
</head>
<body bgcolor="lightblue">
<h2>Welcome to India</h2>
<s:url id="optionsUrl" action="g" />
<sx:autocompleter href="%{#optionsUrl}" loadOnTextChange="true"
loadMinimumCount="3" value="Florida" keyValue="FL" />
</body>
</html>
这里是struts.xml
:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="json-default">
<action name="g" class="com.AutoCompleter">
<result type='json'>
<param name="root">options</param>
</result>
</action>
</package>
</struts>
这是我的行动课:
package com;
import java.util.HashMap;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
public class AutoCompleter extends ActionSupport {
public Map<String, String> getOptions() {
System.out.println("Hello");
Map<String,String> options = new HashMap<String,String>();
options.put("Florida", "FL");
options.put("Alabama", "AL");
return options;
}
}