有关 Struts 操作映射的帮助

发布于 2024-09-04 06:10:16 字数 6347 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新一帅帅 2024-09-11 06:10:16

我认为问题出在 while 循环内的 html:form 标记。将其从循环中取出并尝试。

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

压抑⊿情绪 2024-09-11 06:10:16

如果在 web.xml 中 *.do/ 是类似的东西,那么

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

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

这取决于 url 模式中的前缀,那么这应该与表单操作中的前缀相同。

我希望它能帮助你

if in web.xml the <url-pattern>*.do/<url-pattern> is something like that then in

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

please 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文