It's not a secret anymore!*
The moose likes Struts and the fly likes Struts in action example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts in action example" Watch "Struts in action example" New topic
Author

Struts in action example

Al garton
Greenhorn

Joined: Dec 23, 2011
Posts: 4
Hi all. I'm new with Struts. I've been reading "Struts in action" book. I'm modifying the first example so that I can enter my name, but also my last name. Something pretty easy and really pisses me off, cause I cant get it working.

Theoretically:

"NameCollector.jsp"

...
<body>


<h4>Enter your name so that we can customize a greeting just for you!</h4>
<s:form action="HelloWorld">
<s:textfield name="namee" label="Your name"/>
<s:textfield name="apellido" label="Your lastname"/>
<s:submit/>
</s:form>


</body>

...
I've added "apellido" (Lastname in spanish xD) and +e to name (Just to check if it kept working).

"HelloWorld.java"


package manning.chapterTwo;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport {


private static final String GREETING = "Hello ";



public String execute() {

setCustomGreeting( GREETING + this.getNamee() + " " + getApellido());


return "SUCCESS";
}


private String apellido;

public String getApellido() {
return apelllido;
}

public void setApellido(String apellido) {
this.apellido = apellido;
}

private String namee;

public String getNamee() {
return namee;
}

public void setNamee(String namee) {
this.namee = namee;
}

private String customGreeting;

public String getCustomGreeting()
{
return customGreeting;
}

public void setCustomGreeting( String customGreeting ){
this.customGreeting = customGreeting;
}
}


"struts.xml"

...

<action name="HelloWorld" class="manning.chapterTwo.HelloWorld">
<result name="SUCCESS">/chapterTwo/HelloWorld.jsp</result>
</action>

...

"Helloworld.jsp"
...
<body>



<h3>Custom Greeting Page modificado</h3>
<h4><s:property value="customGreeting"/></h4>


</body>
...


So, I call from a Menu "NameCollector.jsp" (strust.xml does, really).
I load my name and last name.
I get "null" in my output string. Actually, I get "Hello null".

And in my console:

Dec 23, 2011 8:42:06 PM com.opensymphony.xwork2.interceptor.ParametersInterceptor setParameters
SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'apellido' on 'class manning.chapterTwo.HelloWorld: Error setting expression 'apellido' with value '[Ljava.lang.String;@12164ea'
Dec 23, 2011 8:42:06 PM com.opensymphony.xwork2.interceptor.ParametersInterceptor setParameters
SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'namee' on 'class manning.chapterTwo.HelloWorld: Error setting expression 'namee' with value '[Ljava.lang.String;@11b456f'


Does anyone know why I get this?. It used to work fine just with name property. I added one "e" to check if it still worked (Changed it everywhere I thought it was necesary) but it stopped working and return a null.

Something i should know?

Thanks in advance! and Marry Christmas!

Mathew.
Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

Looks like you may not be using default-stack for your interceptors. Post your whole struts.xml
Al garton
Greenhorn

Joined: Dec 23, 2011
Posts: 4
Thanks for your reply Jesus.
There:


"struts.xml"

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.devMode" value="true" />


<package name="default" namespace="/" extends="struts-default">
<action name="Menu">
<result>/menu/Menu.jsp</result>
</action>
</package>

<include file="manning/chapterTwo/chapterTwo.xml"/>

</struts>

"chapterTwo.xml"

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<package name="chapterTwo" namespace="/chapterTwo" extends="struts-default">


<action name="Name">
<result>/chapterTwo/NameCollector.jsp</result>
</action>


<action name="HelloWorld" class="manning.chapterTwo.HelloWorld">
<result name="SUCCESS">/chapterTwo/HelloWorld.jsp</result>
</action>

</package>

</struts>


I don't really understand what you meant. I know the concept of interceptors, but "default-stack"?

Thanks!

Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

What happens if you were to change:



to:

Al garton
Greenhorn

Joined: Dec 23, 2011
Posts: 4
Same result Jesus.

I don't really have a clue of what is going on.... And its pretty damm simple.
I would attach the war file, but it's size is 3.3MB. Maybe you could take a look and figure out whats the issue.

I just upload the zipped project, without the /lib.

PS: Attaching is not possible, because of file extension. Maybe i can send it to your mail.

Thanks!
Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

well it looks right to me. You should be hitting:

http://localhost:8080/chapterTwo/Name

Then that form hits:

/chapterTwo/HelloWorld

All your getters and setters are public and named correctly. So I don't see anything wrong here ... I would recommend to turn on trace, it seems your struts jars may not all be deployed correctly or you are missing something. Your packages extend struts-default but I have a feeling that something is from the struts2 jars is missing.

Al garton
Greenhorn

Joined: Dec 23, 2011
Posts: 4
Ya, I also thought everything was alright. Thanks for your help.

Something else, is there anyway to debug similar as the common debugging that i'm used to perform when programming in java for desktop?. I've already tried debugging but it actually was never successful. I'm using Eclipse.
Something I should take into account, besides "Right click ->Debug as -> Debug on server"?.

Thanks for you patience.!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts in action example