javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean

假如想象 提交于 2019-12-10 11:54:16

问题


I am trying to build a simple struts application where I am trying to print a string value from a java action to jsp using form beans.

first.jsp

 <%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>

    <body>
        Welcome!!!!!!!!

        <bean:write name="myForm" property="st"/>
    </body>
</html>

struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
        "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>

    <form-beans>
        <form-bean name="myForm" type="com.myForm" />
    </form-beans>

    <action-mappings>
        <action path="/view" name="myForm" type="com.myAction" validate="false">
                <forward name="success" path="/first" />
        </action>
        <action path="/view"
                forward="/view.jsp"/>
        <action path="/first"
                forward="/first.jsp" />
    </action-mappings>
</struts-config>

myForm.java

package com;

public class myForm extends org.apache.struts.action.ActionForm {

    private String st;

    public String getSt()
    {
        return st;
    }

    public void setSt(String st)
    {
        this.st=st;
    }

    public myForm(String st)
    {
        this.st=st;
    }
}

myAction.java

package com;

import java.io.IOException;
import javax.servlet.ServletException;
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;
import com.myForm;

public class myAction extends org.apache.struts.action.Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

        myForm form1=(myForm) form;

        String s="Karthikeyan";

        System.out.println("Hello "+s);

        form1.setSt(s);

        //RequestDispatcher reqDispatcher = getRequestDispatcher("view.jsp");
        //reqDispatcher.forward(request,response);




        return (mapping.findForward("success"));
    }
}

These are the files of importance, hence I have not added the files web.xml and view.jsp as I am sure the error is concerned one the files' code that I have posted. The error I am getting is :

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "myForm" in any scope

I don't know why I am encountering the error as I am defining it in the struts-config.xml. Please help.

来源:https://stackoverflow.com/questions/23133457/javax-servlet-servletexception-javax-servlet-jsp-jspexception-cannot-find-bean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!