处理完邮件请求后,页面上没有填充数据

时间:2015-08-13 07:17:09

标签: spring jsp model-view-controller

它显示正确发送get请求时的数据但是当我使用post requset保存数据时再次显示页面数据不会出现在页面上

这是我的控制器代码

@RequestMapping(value = "/incident", method = RequestMethod.GET)
public String add_incident(Model model,HttpSession session) {

    try{
    List<AddIncident> fetchincident = incService.fetchIncident();
    String user_id = ""+session.getAttribute("session");

    List<AddIncident> fetchuserincident = incService.fetchuserincident(user_id);

    //group work

            User user = new User();
    model.addAttribute("user", user);

    List<User> fetchListByUsername = userService.findListByUserName(user_id);

    String department = fetchListByUsername.get(0).getDepartment();
    List<AddIncident> fetchgroupincident = incService.fetchgroupincident(department);

    System.out.println(fetchgroupincident.get(0).getAssignTo());
    System.out.println(fetchgroupincident.get(0).getSeverity());
    model.addAttribute("fetchincident", fetchincident);
    model.addAttribute("fetchgroupincident", fetchgroupincident);
    model.addAttribute("fetchuserincident", fetchuserincident);
    }catch(Exception e){
        e.printStackTrace();    }

    AddIncident incident = new AddIncident();
    model.addAttribute("incident", incident);


    return "incident";
}

@RequestMapping(value = "/incident", method = RequestMethod.POST)
public String add_incident(
        @Valid @ModelAttribute("incident") AddIncident incident,
        BindingResult result, Model model,HttpSession session) {
    if (result.hasErrors()) {
        return "incident";
    } else {

        User user=new User();
        System.out.println(""+session.getAttribute("session"));
        String user_id = ""+session.getAttribute("session");
        System.out.println(user_id);

        List<User> fetchListByUsername = userService.findListByUserName(user_id);

        String department = fetchListByUsername.get(0).getDepartment();
        System.out.println(department);

        try{
        List<User> fetchgroupuser = userService.findListByGroup(department);


        ArrayList<String> email=new ArrayList<String>();

        System.out.println(email);
        for(User use:fetchgroupuser){
            email.add(use.getEmail());
        }

        String[] to = new String[email.size()];
        to = email.toArray(to);
        System.out.println(to);

                /*new String[]{"irasoftwares6@gmail.com","bluemagictest@gmail.com"};*/
        String from = "Anurag.yv19@gmail.com";
        String sub= "Incident Management System"; 
        String msgBody="New Incident created"; 
        incService.save(incident);




        emailService.sendEmail(to , from, sub, msgBody);
        }catch(ArrayIndexOutOfBoundsException e){e.printStackTrace();}
        incident_logger.log(INCIDENT, incident.getRef_id()+"   \n Assigned to :"+session.getAttribute("session"));
        model.addAttribute("message", "Saved incident details");
        return "incident";
    }
}

我的jsp代码

<div class="table-responsive" id="inc-table" style="min-height: 280px;">
                <form action="" method="get">
            <div class="input-group">
                <!-- USE TWITTER TYPEAHEAD JSON WITH API TO SEARCH -->
                <input class="form-control" id="system-search" name="q" placeholder="Search for" required>
                <span class="input-group-btn">
                    <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
                </span>
            </div>
        </form>

                <table  class="table table-list-search table-bordered table-stripped table-hover">
                    <thead>
                        <tr>
                            <th>Ref. No.</th>
                            <th>Created</th>
                            <th>Severity</th>
                            <th>State</th>
                            <th>Assigned</th>
                            <th>Est</th>
                            <th>Description</th>
                            <th>Location</th>
                            <th>Config-item</th>
                            <th>Symptom Code</th>
                            <th>Closure Code</th>
                            <th>Submitted BY</th>
                        </tr>
                    </thead>
                        <tbody>
                        <c:forEach var="fetchuserincident" items="${fetchuserincident}">
                        <tr>

                            <td id="1" class="click" ><a href=""/>${fetchuserincident.ref_id}</td>
                            <td>${fetchuserincident.created}</td>
                            <td>${fetchuserincident.severity}</td>
                            <td>${fetchuserincident.state}</td>
                            <td>${fetchuserincident.assignTo}</td>
                            <td>${fetchuserincident.escalation}</td>
                            <td>${fetchuserincident.description}</td>
                            <td>${fetchuserincident.location}</td>
                            <td>${fetchuserincident.config_Item}</td>

                            <td>${fetchuserincident.symptom_code}</td>
                            <td>${fetchuserincident.closure_code}</td>
                            <td>${fetchuserincident.submittedby}</td>
                            <td> <button id="editbtn" class="fa fa-pencil">Edit</button></td>

                            </tr>
                                            </c:forEach>

                    </tbody>

                </table>




            </div>

            <hr>
            <br>
                    我的小组工作                                                                                                                                                                                                                                                                                             参考。没有。                                 创建                                 严重                                 州                                 分配                                 美东时间                                 描述                                 地点                                 配置项                                 症状代码                                 关闭代码                                 由...所提交                                                                                                                                                                              $ {} fetchgroupincident.ref_id                                 $ {} fetchgroupincident.created                                 $ {} fetchgroupincident.severity                                 $ {} fetchgroupincident.state                                 $ {} fetchgroupincident.assignTo                                 $ {} fetchgroupincident.escalation                                 $ {} fetchgroupincident.description                                 $ {} fetchgroupincident.location                                 $ {} fetchgroupincident.config_Item                                     $ {} fetchgroupincident.symptom_code                                 $ {} fetchgroupincident.closure_code                                 $ {} fetchgroupincident.submittedby                                          编辑                                                                                                                                 

0 个答案:

没有答案