2

我想显示网格,但是当我执行 jsp 页面时,既没有显示任何网格,也没有显示任何数据...
JSP 页面:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome !</title>


</head>
<body>
    <s:url id="remoteurl" action="listStudents.action" />
    <sjg:grid id="gridtable" caption="Students..." dataType="json"
        href="%{remoteurl}" pager="true" gridModel="listStudentUtils"
        rowNum="10" navigator="true" navigatorAdd="false"
        navigatorDelete="false" navigatorEdit="false" navigatorRefresh="true"
        navigatorSearch="false" navigatorView="false" rownumbers="true"
        rowList="10,20,30" viewrecords="true" autowidth="true">
        <sjg:gridColumn name="object.studentID" hidden="true" search="false"
            key="true" index="studentID" title="Student ID" sortable="false" />
        <sjg:gridColumn name="object.studentName" align="left"
            index="studentName" title="Student Name" sortable="false" />
        <sjg:gridColumn name="object.studentAddress" align="left"
            index="studentAddress" title="Student Address" sortable="false" />
    </sjg:grid>
</body>
</html>  

下面是我的动作课

package pckg.action;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class StudentAction extends ActionSupport {
    Student st;
    List<Student> listStudentUtils;

    public StudentAction() {
        // TODO Auto-generated constructor stub
    }

    public Student getSt() {
        return st;
    }

    public void setSt(Student st) {
        this.st = st;
    }

    public List<Student> getListStudentUtils() {
        return listStudentUtils;
    }

    public void setListStudentUtils(List<Student> listStudentUtils) {
        this.listStudentUtils = listStudentUtils;
    }

    @Override
    public String execute() throws Exception {
        String type = "";
        System.out.println("Into Action Class...");
        // TODO Auto-generated method stub
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/sample", "root", "siddheshkk");
            System.out.println("Driver Loaded");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("select * from emp");
            listStudentUtils = new ArrayList<Student>();
            while (rs.next()) {
                listStudentUtils.add(new Student(rs.getString("name"), rs
                        .getString("password")));
            }
            System.out.println("Data Collected na Baa...!!");
            type = SUCCESS;
            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }

        return type;
    }

}  

下面是我的 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" />
    <constant name="struts.ui.theme" value="simple" />
    <package name="myPack" extends="struts-default,json-default">
        <interceptors>
            <interceptor-stack name="defaultStack">
                <interceptor-ref name="params">
                    <param name="acceptParamNames">
                        (\[\\d+\]\\.)*\\w+((\\.\\w+)|(\[\\d+\])|(\(\\d+\))|(\['\\w+'\])|(\('\\w+'\)))*
                    </param>
                </interceptor-ref>
            </interceptor-stack>
        </interceptors>

        <action name="listStudents" class="pckg.action.StudentAction">
            <interceptor-ref name="defaultStack" />
            <result name="success" type="json">index.jsp</result>
            <result name="error" type="json">error.jsp</result>
        </action>
    </package>
</struts> 

没有显示错误。它没有执行动作类。我添加了 3 个 jar 文件以及基本的 struts2 jar 文件。它们是:

struts2-jquery-grid-plugin-3.1.1.jar  
struts2-jquery-plugin-3.1.1.jar  
struts2-json-plugin-2.3.20.jar
4

1 回答 1

2

我通过加载 jquery 标签解决了我的问题

<%@taglib uri="/struts-jquery-tags" prefix="sj" %>  

并将下面的行放在 head 标签中

<sj:head jqueryui="true" jquerytheme="redmond" />
于 2016-05-19T11:41:01.090 回答