有关 Struts 操作映射的帮助
我的 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>
当我单击该链接时,除了页面上的菜单外,我什么也没有得到。页面的文本标题甚至不显示。
注册.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>
显示注册操作:
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");
}
}
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");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题出在 while 循环内的 html:form 标记。将其从循环中取出并尝试。
I think problem is with html:form tag inside the while loop. take out that out of the loop and try.
如果在 web.xml 中
*.do/
是类似的东西,那么请提及
html:form action="**/showEnrolled .do**">
这取决于 url 模式中的前缀,那么这应该与表单操作中的前缀相同。
我希望它能帮助你
if in web.xml the
<url-pattern>*.do/<url-pattern>
is something like that then inplease mention
html:form action="**/showEnrolled.do**">
It depend on what prefix in there at the url pattern then this should be same prefix in form action.
I hope it help you