Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用Java Struts填充fullcalendar事件数据_Jquery_Json_Ajax_Fullcalendar_Struts 1 - Fatal编程技术网

Jquery 使用Java Struts填充fullcalendar事件数据

Jquery 使用Java Struts填充fullcalendar事件数据,jquery,json,ajax,fullcalendar,struts-1,Jquery,Json,Ajax,Fullcalendar,Struts 1,我一直在关注这篇博客文章 但是,我的日历没有显示。我想从数据库中检索数据,然后使用JSON输出它(目前我已经在中硬编码了测试数据),然后使用$.post()检索JSON数据并用它填充日历 我的密码- 动作映射定义 <action path="/getCalendarEvents" scope="request" type="com.action.struts.AjaxAction" validate="false"/> Aja

我一直在关注这篇博客文章

但是,我的日历没有显示。我想从数据库中检索数据,然后使用JSON输出它(目前我已经在中硬编码了测试数据),然后使用$.post()检索JSON数据并用它填充日历

我的密码-

动作映射定义

<action path="/getCalendarEvents" 
        scope="request" 
        type="com.action.struts.AjaxAction"  
        validate="false"/>
AjaxMoreUtil.java

public class AjaxAction extends ActionForward{
     public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
                        AjaxMoreUtil.getAllEvents(request, response);
                return null;
        }
}
public class AjaxMoreUtil {
    public static void getAllEvents(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ArrayList<CalendarDTO> allEventList = new ArrayList<CalendarDTO>();

        CalendarDTO c = new CalendarDTO();
        c.setId(1);
        c.setStart("2017-06-21");
        c.setEnd("2017-06-26");
        c.setTitle("Task in Progress"); 

        allEventList.add(c);

        CalendarDTO d = new CalendarDTO();
        d.setId(2);
        d.setStart("2017-06-01");
        d.setEnd("2017-06-10");
        d.setTitle("Task in Progress");

        allEventList.add(d);

        String json = new Gson().toJson(allEventList);
        System.out.println("json value " + json);
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(json);
    }
}
公共类AjaxMoreUtil{
公共静态void getAllEvents(HttpServletRequest请求、HttpServletResponse响应)引发异常{
ArrayList allEventList=新的ArrayList();
CalendarDTO c=新CalendarDTO();
c、 setId(1);
c、 setStart(“2017-06-21”);
c、 setEnd(“2017-06-26”);
c、 setTitle(“任务进行中”);
allEventList.添加(c);
CalendarDTO d=新CalendarDTO();
d、 setId(2);
d、 设置启动(“2017-06-01”);
d、 setEnd(“2017-06-10”);
d、 setTitle(“任务进行中”);
allEventList.添加(d);
字符串json=new Gson().toJson(allEventList);
System.out.println(“json值”+json);
setContentType(“应用程序/json”);
响应。setCharacterEncoding(“UTF-8”);
response.getWriter().write(json);
}
}

当我运行应用程序时,我得到了一个404的帖子,没有显示任何内容

我最终用一个请求变量解决了这个问题

在AjaxMoreUtil.java中,我将每个事件放入ArrayList中

List l = new ArrayList();
CalendarDTO c = new CalendarDTO();
c.setStart("2017-07-05");
c.setEnd("2017-07-08");
c.setTitle("event1"); 

l.add(c);
然后,我使用google的Gson JSON转换器将该列表转换为JSON字符串

String resultSet = gson.toJson(l);

request.setAttribute("rs", resultSet);
request.getRequestDispatcher("/pages/Scheduler.jsp").forward(request,response);
在.jsp中,我获取请求变量并将其设置为javascript变量

var rs = JSON.stringify(<%=rs%>);

这正确地显示了日历中的信息。

我无法说明为什么您的请求会得到404,因为我对struts一无所知。但就日历设置而言,你走错了方向。您应该在页面加载时声明日历,然后“events”属性应该是运行POST方法的函数。您的服务器应该接受“开始”和“结束”参数,它使用这些参数按日期筛选事件。这样,当日历的视图/日期发生更改时,日历将自动获取相关日期的事件。就目前情况而言,你一次把它们全部取出来,这是无效的……而且随着时间的推移,效率会越来越低,而且你有大量以前发生过的事件的历史,而人们通常不会真正看到这些事件。有关更多详细信息,请参阅和。
var rs = JSON.stringify(<%=rs%>);
events: JSON.parse(rs)