【问题标题】:after redirect by ReguestDispatcher page context isn't displayed (white page)?ReguestDispatcher 页面上下文重定向后不显示(白页)?
【发布时间】:2014-03-30 22:42:58
【问题描述】:

我从项目页面移动到当前项目的任务。

我需要重定向到所选项目的任务页面。它被重定向到 ok url,但页面不显示。它显示白页:

URL 正确,参数传递正确。

这里是projectTable.jsp的片段:

<form action="${pageContext.request.contextPath}/manager/projectstable" method="post" id="projectstable-form">
    <div class="row">
        <div class="table-responsive tile col-md-10 col-sm-12 col-xs-12 col-md-offset-1">
            <table class="table table-striped table-hover">
            <!-- Table -->
            <thead>
            <tr>
                <th></th>
                <th>#</th>
                <th><fmt:message key="project.name" /></th>
                <th><fmt:message key="project.description" /></th>
                <th><fmt:message key="project.notes"/></th>
                <th><fmt:message key="project.tasks"/></th>
            </tr>
            </thead>

            <tbody>
            <c:forEach var="project" items="${requestScope.projects}">
                <tr>
                    <td>
                        <label class="checkbox" for="checkbox${project.id}">
                            <input type="checkbox" name="checkedProjects" value="${project.id}"
                                   id="checkbox${project.id}" data-toggle="checkbox">
                        </label>
                    </td>
                    <td>${project.id}</td>
                    <td>${project.projectName}</td>
                    <td>${project.description}</td>
                    <td>${project.notes}</td>
                    <td><a href="${pageContext.request.contextPath}/manager/taskstable?project_id=${project.id}"
                        class="btn btn-info btn-xs"><fmt:message key="project.see.tasks"/></a>
                    </td>

它在浏览器中的外观:

移动被实现为链接按钮 - See tasks

这是 TasksTableServlet 的 sn-p:

@WebServlet("/manager/taskstable")
@MultipartConfig
public class TasksTableServlet extends HttpServlet {
    private static Logger log = Logger.getLogger(AddTaskServlet.class);
    private TaskService taskService;
    private List<Task> tasks;
    private static final String DATE_FORMAT = "MM/dd/yyyy";

    public static final String ATTRIBUTE_TO_MODEL = "tasksList";
    public static final String PAGE_OK = "/pages/manager/tasksTable.jsp";
    public static final String PAGE_ERROR_URL = "error";

    @Override
    public void init() throws ServletException {
        taskService = new TaskService();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            if (request.getParameter("project_id") != null) {
                System.out.println("ID: " + request.getParameter("project_id"));
                updateTable(request);
                if (!tasks.isEmpty()) {
                    request.setAttribute(ATTRIBUTE_TO_MODEL, tasks);
                    request.getRequestDispatcher(PAGE_OK);
                    return;
                }
            }
        } catch (Exception e) {
            log.error(e);
        }
        response.sendRedirect(PAGE_ERROR_URL);
    }

private void updateTable(HttpServletRequest request) {
    try {
        int id = Integer.parseInt(request.getParameter("project_id"));
        tasks = taskService.getByProjectId(id);
    } catch (DAOException e) {
        log.error(e);
    }
}

这里是content of tasksTable.jsp

我不明白为什么这个页面没有显示?在我看来,它应该可以工作。

如何解决这个问题?

【问题讨论】:

    标签: jsp servlets requestdispatcher


    【解决方案1】:

    请求调度员只是第一步。您还必须实际转发。

    request.getRequestDispatcher(PAGE_OK).forward(request, response);
    return;
    

    【讨论】:

      猜你喜欢
      • 2020-01-30
      • 1970-01-01
      • 2011-12-17
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 2015-05-13
      • 1970-01-01
      相关资源
      最近更新 更多