【发布时间】:2012-03-22 05:25:59
【问题描述】:
我编写了这段代码,它返回一个 Json 字符串。它包含一组值(名称)。现在我想使用 Dojo 数据网格在 jsp 页面上显示这些值。我不知道如何使用这个返回的 Json 字符串作为 Dojo 网格的数据。以及如何格式化表格结构。我还希望当我单击表中的特定行(在这种情况下仅包含一个列 - 根据我的查询的员工姓名)时,会打开一个新窗口(可能是一个新的 JSP 页面)。怎么做?请帮我写代码。谢谢。
填充文本框.java
package MyPackage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
public class PopulateTextbox {
Gson gson = new Gson();
String temp;
List <String>rowValues = new ArrayList<String>();
String[] contactListNames;
Connection con=null;
Statement st=null;
ResultSet rs=null;
public String method(){
try{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
String db = "jdbc:odbc:Practice_Database";
con = DriverManager.getConnection(db,"","");
st = con.createStatement();
String sql = "SELECT Emp_Name FROM EmployeeSearch";
rs = st.executeQuery(sql);
while(rs.next()){
rowValues.add(rs.getString("Emp_Name"));
}
contactListNames = (String[]) rowValues.toArray(new String[rowValues.size()]);
temp = gson.toJson(contactListNames);
}catch(Exception e){System.out.println(e);}
/*finally{
try {
if(con!=null)con.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(rs!=null)rs.close();
} catch (SQLException e) {
e.printStackTrace();
}try {
if(st!=null)st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}*/
return temp;
}
}
【问题讨论】:
标签: java json jsp datagrid dojo