简体   繁体   English

无法在struts中找到前进

[英]Unable to find forward in struts

FormBackup.java FormBackup.java

package beans;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class FormBackup extends ActionForm{

    private String name;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Override
    public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
        ActionErrors ae = new ActionErrors();
        if(name.equals(""))
            ae.add("name",new ActionMessage("msg"));
        return ae; 
    }
}

FormController.java FormController.java

package beans;
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;

public class FormController extends Action{

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        
        String name=request.getParameter("name");
        request.setAttribute("res", "Hello..." +name);
        return mapping.findForward("success");  
    }
}

index.jsp索引.jsp

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

<h1>Validation Form</h1>

<html:form action="Hello">
    Name:<html:text property="name"/><html:errors/>
    <html:submit value="submit"/>
</html:form>

success.jsp成功.jsp

<%=request.getAttribute("res")%>

struts-config.xml struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<struts-config>

    <form-beans>
        <form-bean name="HF" type="beans.FormBackup" />
    </form-beans>
    <action-mappings>
        <action path="/Hello" name="HF" input="/index.jsp"
            type="beans.FormController"></action>
        <forward name="success" path="/success.jsp" redirect="true" />
    </action-mappings>
    <message-resources parameter="beans.Messages" />
</struts-config>

web.xml web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee;http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>FirstStrutsExample</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>actionservlet</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>actionservlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <jsp-config>
        <taglib>
            <taglib-uri>/tags/struts-html</taglib-uri>
            <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>

I'm new to Struts here I have created simple hello form in which index page gets executed, and then when I'm trying to submit the form it shows unable to find "success" forward.我是 Struts 的新手,我创建了简单的 hello 表单,在该表单中执行索引页面,然后当我尝试提交表单时,它显示无法找到"success"转发。 I don't know where I had the exact error.我不知道我在哪里有确切的错误。 can someone can help me with this.有人可以帮助我吗? when I hit the submit button it shows me like当我点击提交按钮时,它显示我喜欢

"org.apache.struts.action.ActionMapping findForward WARNING: Unable to find 'success' forward." “org.apache.struts.action.ActionMapping findForward 警告:无法找到‘成功’转发。”

In the configuration struts-config.xml you didn't added <forward> to the <action> Tag.在配置 struts-config.xml 中,您没有将<forward>添加到<action>标记。

<action path="/Hello" name="HF" input="/index.jsp" type ="beans.FormController">
<forward name ="success" path ="/success.jsp"/>
</action>

There should be XML parsing errors at sturtup because this document doesn't comply struts-config.DTD . sturtup 应该有 XML 解析错误,因为该文档不符合struts-config.DTD

In the struts-config.xml you should include a correct doctype against which DTD is validated.在 struts-config.xml 中,您应该包含一个正确的文档类型,根据该文档类型验证 DTD。

<!DOCTYPE struts-config PUBLIC     
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "struts-config_1_3.dtd">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM