Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2010
    Posts
    38
    Rep Power
    0

    Default struts example will not run

    hi friends i am trying to run one struts example but it will not run..

    first i will create one index.jsp page

    INDEX.jsp

    <%@ page language="java" %>
    <%@ page taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

    <html>
    <head>
    <title>Sample Struts Application </title>
    </head>
    <body>
    <htmp:form action="Name" name="nameForm" type="example.NameForm">
    <table width="80%" border="0">
    <tr>
    <td>Name : </td>
    <td><html:text property="name" /></td>
    </tr>

    <tr>
    <td><html:submit /></td>
    </tr>
    </table>
    </html:form>
    </body>
    </html>

    2) then i will create second page displayname.jsp

    Displayname.jsp

    <html>
    <head>
    <title>Sample Struts Display Name</title>
    </head>
    <body>
    <table width="80%" border="0">
    <tr>
    <td> Hello Dharmit <%=request.getAttribute("NAME")%> !!</td>
    </tr>
    </table>
    </body>
    </html>

    3) then i will create to more java file for fetching the data..

    NameForm.java

    package example;

    import javax.servlet.http.HttpServlet.Request;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;

    public class NameForm extends ActionForm
    {
    private String name = null;

    public String getName()
    {
    return(name);
    }

    public void setName(String name)
    {
    this.name = name;
    }

    public void reset(ActionMapping mapping,HttpServlet request)
    {
    this.name = null;
    }
    }


    NameAction.java

    package example;

    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;

    public class NameAction extends Action
    {
    public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
    {
    String target = new String(" SuccessFully ");

    if( form != null)
    {
    NameForm nameForm = (NameForm)form;
    String name = nameForm.getName();
    }


    if( name==null)
    {
    target = new String(" Failure ");
    }
    else
    {
    request.setAttribute("NAME",name);
    }

    return(mapping.findforward(target));
    }
    }


    4) then i will create struts-config.xml file.....

    struts-config.xml

    <?xml version="1.0" encoding="utf-8"?>

    <form-bean name="nameForm" type="example.NameForm"/>

    <action path="/Name" type="example.NameAction" name="nameForm" input="/index.jsp">
    <forward name="success" path="/displayname.jsp"/>
    <forward name="failure" path="/index.jsp"/>
    </action>

    5) also putting sum code in web.xml file..

    web.xml

    <taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>

    <servlet>
    <servlet-name>action</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>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    6) this all is puting into tomcate...

    and after running the webbrowser i will getting....

    So please help me for running this struts example.

    Thank you :)

  2. #2
    anarayana is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default

    in struts-config.xml file the index.jsp is replace with INDEX.jsp nd then try to execute that

  3. #3
    Ramanjaneyulu is offline Member
    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0

    Default

    mcajavaprogramer,

    Can you please mention the error you are getting?

  4. #4
    anarayana is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default

    struts-config.xml

    <?xml version="1.0" encoding="utf-8"?>

    <form-bean name="nameForm" type="example.NameForm"/>

    <action path="/Name" type="example.NameAction" name="nameForm" input="/index.jsp">
    <forward name="success" path="/displayname.jsp"/>
    <forward name="failure" path="/index.jsp"/>
    </action>

  5. #5
    anarayana is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default

    in struts-config.xml file the index.jsp is replace with INDEX.jsp nd then try to execute that

    struts-config.xml

    <?xml version="1.0" encoding="utf-8"?>

    <form-bean name="nameForm" type="example.NameForm"/>

    <action path="/Name" type="example.NameAction" name="nameForm" input="/index.jsp">
    <forward name="success" path="/displayname.jsp"/>
    <forward name="failure" path="/index.jsp"/>
    </action>

Similar Threads

  1. decorator.jsp problem building Struts Menu in JSP when Struts action is used
    By dkirvan in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-29-2010, 06:33 AM
  2. Php in struts
    By sharevenki in forum Web Frameworks
    Replies: 0
    Last Post: 04-25-2009, 02:04 PM
  3. Struts
    By ucan_aps in forum Web Frameworks
    Replies: 0
    Last Post: 09-26-2008, 06:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •