不调用Struts1.2动作类

时间:2013-09-18 06:53:50

标签: java struts

这里我给我的代码我没有得到输出但是调用了动作但是没有调用动作类。我想做什么请帮助我。我在网址中得到的是

http://vpcl014:8080/StrutsExamples/loginPojoClass.do

但是我的文件没有显示而且actioncalss没有调用。我该做什么 :( PojoClass。

import org.apache.struts.action.ActionForm;

public class LoginPojo extends ActionForm {

    /**
     * 
     */
    private static final long serialVersionUID = 962636910569104889L;
    private String username;
    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}

行动类:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;    
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


// action mapping class for the action.
public class Pojoaction extends Action {

    // method for the mapping the action.
    public ActionForward execute(ActionForm form, ActionMapping mapping,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        System.out.println("Action is called..:D");
        LoginPojo loginPojo = new LoginPojo();
        loginPojo.setUsername("Username");
        loginPojo.setPassword("Password");
        return mapping.findForward("success");
    }

}

struts-cfg.xml文件就在这里。

<form-beans>
    <form-bean name="LoginPojo" type="com.kishan.modelPojo.LoginPojo"></form-bean>
    <form-bean name="LoginPojoSuccess"
        type="com.kishan.modelPojo.LoginPojo.LoginPojoSuccess"></form-bean>
</form-beans>
<action-mappings>
    <action path="/Forword" forward="/LoginPojo.jsp"></action>
    <action name="LoginPojo" path="/loginPojoClass" scope="session"
        type="com.kishan.modelPojo.Pojoaction" input="/LoginPojo.jsp"
        validate="false">
        <forward name="success" path="/LoginPojoSuccess.jsp"
            redirect="true">
        </forward>
    </action>
</action-mappings>
<message-resources parameter="com.kishan.struts.ApplicationResources" />

我调用该方法的jsp文件。                       

    <body>
        <html:form action="/loginPojoClass">
            Username:<html:text property="username"></html:text>
            <br />
            Password:<html:password property="password"></html:password>
            <br/><html:submit value="Submit"></html:submit>
        </html:form>

        This is my JSP page.
        <br>
    </body>
</html>

最后我的index.jsp,我正在进行第一次前进行动

 <html>
    <head>
        <base href="<%=basePath%>">

        <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    </head>

    <body>
        <html:link action="/Forword.do">GOTO FORM</html:link>

        <br>
    </body>
</html>

1 个答案:

答案 0 :(得分:2)

我不知道它是如何完成的,但我找到了相同的解决方案。

将一些参数替换为方法。那是。

我将ServletRequest替换为HttpServletRequest,并使用覆盖表示法来覆盖类方法。并且它得到了解决我不知道原因如何..

@override
public ActionForward execute(ActionForm form, ActionMapping mapping,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception() {

}