Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Struts2 Validation troubles

Holl Gerald

2006-12-19


Hello,

I tried a little example on validation with struts2.
Here is the Login.jsp:
<%@(protected)" %>
<html>  
 <head>
   <title>Login</title>
 </head>
 <body>
   <h2>Login</h2>
   <s:form id="login" action="Login">
     <p><s:textfield label="%{getText('username')}"
name="username" required="true"/></p>
     <p><s:password label="%{getText('password')}"
name="password" maxlength="255" required="true"/></p>
     <p><s:submit value="Login"/></p>
   </s:form>
 </body>
</html>

And the Login.java action class:
public class Login extends ActionSupport {
 @Override
 public String execute() throws Exception {
   System.out.println("execute()");
   return SUCCESS;
 }
}

The Login--validation.xml looks like this:
<validators>
<field name="username">
  <field-validator type="requiredstring">
     <message key="requiredstring"/>
  </field-validator>
</field>
<field name="password">
  <field-validator type="requiredstring">
     <message key="requiredstring"/>
  </field-validator>
</field>
</validators>


And last the struts.xml:
<struts>
 <!-- Include framework defaults (from Struts 2 JAR). -->
 <include file="struts-default.xml" />
 <!-- Configuration for the default package. -->
 <package name="mypackage" extends="struts-default">
   <action name="Login" class="misc.Login">
     <result name="input">/Login.jsp</result>
     <result name="success">/Main.jsp</result>
   </action>
 </package>
</struts>


The problem is that I always get back on the Login page although I
entered correct credentials ...
It seems that the result=success never occurs.

Any ideas what's wrong there?


Thanks,
Gerald

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.