wood burning stoves 2.0*
The moose likes Struts and the fly likes new to struts - problem in small struts example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "new to struts - problem in small struts example" Watch "new to struts - problem in small struts example" New topic

new to struts - problem in small struts example

Bala Raju Mandala
Ranch Hand

Joined: Sep 21, 2006
Posts: 40
Hi All,

I am new to struts, i am practicing using some examples. I was struck with a program. Please help me where i am wrong. I am pasting all the files here.

On Tomcat console i am able to see only one statement from the ActionForm. Later the control is not going to Action class. Can any body help me to solving this?

<form action='welcome.do' method='post'>
Enter your name:
<input type="text"
name="myname" value="">
<input type="submit"
name="submit" value="Proceed">
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"


<form-bean name="welcomeForm" type="deccan.WelcomeForm"/>

<forward name="success" path="/welcome.jsp" />
<forward name="failure" path="/index.html" />

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"





package deccan;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.struts.action.*;

public class WelcomeAction extends Action {
public ActionForward execute(
ActionMapping mapping ,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response )
throws Exception {
ActionForward forward = null;
WelcomeForm welcomeForm = (WelcomeForm)form;
System.out.println("in WelcomeAction");
String v = welcomeForm.getMyname();
System.out.println("in Action name " + v);

if( v == null || v.trim().length() < 1 ) {
return mapping.findForward("failure");
} else {
request.setAttribute("myname", "You are " + v );
return mapping.findForward("success");
package deccan;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.util.*;

public class WelcomeForm extends ActionForm {
private String myname;

public String getMyname() {
System.out.println("in get " + myname);
return myname;

public void setMyname(String value) {
System.out.println("in set " + value);
myname = value;

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ page import="code.WelcomeForm"%>
You entered :
<bean:write name="welcomeForm" property="myname" scope="request"/>
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

The code snippets look exactly fine except for one thing.

This should actually be
Bala Raju Mandala
Ranch Hand

Joined: Sep 21, 2006
Posts: 40
Hey Anand,

Thank you for your reply. I modified the package name but still problem exists like that only. I am able to see only one output on console 'in set'.

It is not at all entering Action class. Please help, i am running out of thoughts
[ March 03, 2008: Message edited by: Bala Raju Mandala ]
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

I personally made a new project and tested the code. It works all fine.
Probably you are missing something somewhere. Well, it's really difficult to comment.
But, please specify the steps that you took to make the project. You have got on some other boat somewhere.
It is sorta covered in the JavaRanch Style Guide.
subject: new to struts - problem in small struts example