我的struts應用程序出現問題,它是一個班級註冊應用程序,當用戶點擊「顯示註冊課程」按鈕時,它應該顯示他們註冊的課程,但它顯示目前沒有任何東西。 Struts/Apache不會返回任何錯誤,它只是顯示一個空白頁面,我無法弄清楚原因。在我的struts-config幫助Struts動作映射
我的動作映射:
<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");
}
}
你在ShowEnrolledAction中有什麼代碼?什麼是enrolled.jsp的內容? – Tommi 2010-06-08 08:38:58
@Tommi我在這些代碼中添加了一些內容,感謝您抽出寶貴時間來看看這些內容,這讓我倍感震驚。 – nicotine 2010-06-08 19:21:29
客戶端HTML是什麼樣的?它不完整嗎?有時它會停止?如果您刪除此代碼: 您的頁面是否呈現結果? –
2010-06-09 11:18:20