views:

181

answers:

1

I am having a problem with my struts application it is a class enrollment app and when the user clicks on a "show enrolled courses" button it is supposed to show the courses they are enrolled in but it shows nothing at the moment. Struts/Apache does not return any errors, it Just shows a blank page and I cannot figure out why.

My action mapping in my 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>

My link to the jsp enrolled.jsp page:

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

When I click the link I get nothing but my menu on the page. The text headings for the page are not even displayed.

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");
    }
}
A: 

I think problem is with html:form tag inside the while loop. take out that out of the loop and try.

RaviG