帮助Struts Action映射

时间:2010-06-08 02:27:35

标签: tomcat struts struts-1

我的struts应用程序出现问题它是一个类注册应用程序,当用户点击“显示注册的课程”按钮时,它应该显示他们注册的课程,但它现在什么都没有显示。 Struts / Apache不会返回任何错误,它只显示一个空白页面,我无法弄清楚原因。

我在struts-config中的行为映射:

    <action 
        path="/showEnrolled"            
        type="actions.ShowEnrolledAction"           
        name="UserFormEnrolled" 
        scope="request" 
        validate="true"         
        input="/students/StudentMenu.jsp"> 
    <forward 
        name="success" 
        path="/students/enrolled.jsp"/> </action>

我对jsp enrolled.jsp页面的链接:

<li><html:form action="/showEnrolled">
<html:hidden property="id" value= "<%=request.getRemoteUser()%>"/> <html:submit value = "View Enrolled Classes"/>
</html:form> </li>

当我点击链接时,我只得到页面上的菜单。页面的文本标题甚至都没有显示。

enrolled.jsp:

<%@ page import="javax.sql.*"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

<html:html>
    <head>
        <title><bean:message key="app.title" /></title>
        <html:base />
    </head>
<body>

    <html:errors />
    <h1>Enrolled Courses for <%=request.getRemoteUser() %></h1>
    <table>
    <tr>
        <td valign="top">
            <jsp:include page="/students/StudentMenu.jsp"/>
        </td>
        <td>
            <table>
            <tr>
                <th>Course Title</th>
                <th>Course ID</th>
                <th>Class ID</th>
                <th>Days</th>
                <th>Start Time</th>
                <th>End Time</th>
                <th>Location</th>
                <th>Instructor</th>
            </tr>           
            <%-- -------- Iteration Code -------- --%>
            <%
                // Get the studentsRowSet
                RowSet crsEnrolled = (RowSet) request.getAttribute("crsEnrolled");

                // Iterate over the RowSet
                while (crsEnrolled.next()) {
            %>
            <tr>
                <html:form action="/dropClass">
                <td>
                    <input type="hidden" name="title" 
                    value="<%=crsEnrolled.getString("title") %>" />
                    <%=crsEnrolled.getString("title") %>
                </td>
                                <td>
                    <input type="hidden" name="courseid" 
                    value="<%=crsEnrolled.getInt("course_number") %>" />
                    <%=crsEnrolled.getInt("course_id") %>
                </td>
                                <td>
                    <input type="hidden" name="classid" 
                    value="<%=crsEnrolled.getInt("class_id") %>" />
                    <%=crsEnrolled.getInt("class_id") %>
                </td>
                                <td>
                    <input type="hidden" name="days" 
                    value="<%=crsEnrolled.getString("date_code") %>" />
                    <%=crsEnrolled.getString("date_code") %>
                </td>
                                <td>
                    <input type="hidden" name="start" 
                    value="<%=crsEnrolled.getTime("start_time") %>" />
                    <%=crsEnrolled.getTime("start_time") %>
                </td>
                                <td>
                    <input type="hidden" name="end" 
                    value="<%=crsEnrolled.getTime("end_time") %>" />
                    <%=crsEnrolled.getTime("end_time") %>
                </td>
                                <td>
                    <input type="hidden" name="location" 
                    value="<%=crsEnrolled.getString("cl_location") %>" />
                    <%=crsEnrolled.getString("cl_location") %>
                </td>
                <td>
                    <input type="hidden" name="instructorfirst" 
                    value="<%=crsEnrolled.getString("first_name") %>" />
                    <%=crsEnrolled.getString("first_name") %>
                    <input type="hidden" name="instructorlast" 
                    value="<%=crsEnrolled.getString("instructor_last") %>" />
                    <%=crsEnrolled.getString("last_name") %>
                </td>
                    <html:hidden property="classId" value="<%=Integer.toString(crsEnrolled.getInt("class_id"))%>" />
                    <html:hidden property="stuId" value="<%=request.getRemoteUser() %>" />
                    <td><html:submit value ="Drop" /></td>                  
                </html:form>
            </tr>
            <%
                }
            %>
            </table>
        </td>   
    </tr>
    </table>

</body>
</html:html>

ShowEnrolledAction:

package actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.EnrollModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.UserFormEnrolled;

public class ShowEnrolledAction extends Action{
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws DbException {

        // Cast the form
        UserFormEnrolled iForm = (UserFormEnrolled) form;
        iForm.setStudentId(request.getRemoteUser());

        // Insert the student
        RowSet crsEnrolled = EnrollModel.getEnrolledClasses(iForm);
        request.setAttribute("crsEnrolled", crsEnrolled);

        return mapping.findForward("success");
    }
}

2 个答案:

答案 0 :(得分:0)

我认为问题在于while循环中的html:form标签。把它取出来试试。

答案 1 :(得分:0)

如果在web.xml中,<url-pattern>*.do/<url-pattern>就像那样

<html:form action="/showEnrolled">
</html:form> 

请提及html:form action="**/showEnrolled.do**">

它取决于url模式中的前缀,然后在表单操作中应该是相同的前缀。

我希望它可以帮到你