You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by TANG Xigen <Xi...@alcatel-sbell.com.cn> on 2007/11/08 02:26:38 UTC
struts2 Action pojo can not bind beans
Hi all,
my new work is about transfer my web layer to struts2, and when
i write my first struts code, i find strut2 action pojo can not bind
it's beans when a web page post a form
my detail configuration below
========================================================================
=====
struts.xml
========================================================================
=====
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"struts-2.0.dtd">
<struts>
<package name="com.dztalk.client.webflow.struts.pojos"
extends="struts-default">
<interceptors>
<interceptor name="LanguageFocusInterceptor"
class="com.dztalk.client.webflow.struts.interceptors.LanguageFocusInterc
eptor"></interceptor>
</interceptors>
<action name="Logon!*" method="{1}"
class="com.dztalk.client.webflow.struts.pojos.LoginAction">
<interceptor-ref
name="LanguageFocusInterceptor"></interceptor-ref>
<result
name="start">/pages/generals/Logon.jsp</result>
<result
type="redirect-action">/pages/generals/Logon.jsp</result>
<result
name="success">/pages/generals/Logon.jsp</result>
</action>
<action name="Regist!*" method="{1}"
class="com.dztalk.client.webflow.struts.pojos.RegistAction">
<interceptor-ref
name="LanguageFocusInterceptor"></interceptor-ref>
<result
name="start">/pages/generals/Regist.jsp</result>
<result
type="redirect-action">/pages/generals/Regist.jsp</result>
<result
name="success">/pages/generals/Regist.jsp</result>
</action>
</package>
</struts>
====================
web.xml
====================
<web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>dztalk-webflow</display-name>
<servlet>
<servlet-name>InitializeServlet</servlet-name>
<servlet-class>com.dztalk.client.webflow.struts.initialized.InitializedI
nvocationHandle</servlet-class>
</servlet>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>hbm-session</filter-name>
<filter-class>com.dztalk.client.jpa.hibernate.utils.HibernateSessionFilt
er</filter-class>
</filter>
<filter-mapping>
<filter-name>hbm-session</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-cla
ss>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<jsp-config>
<taglib>
<taglib-uri>/s</taglib-uri>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
========================================================================
==
LoginAction.java
========================================================================
==
package com.dztalk.client.webflow.struts.pojos;
@SuppressWarnings("serial")
public class LoginAction extends PlatformActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println(getUsername());
return SUCCESS;
}
public String doLogin(){
System.out.println(getUsername());
return SUCCESS;
}
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
==========================================================
logon.jsp
==========================================================
<%@ page language="java" contentType="text/html; charset=GB2312"
pageEncoding="gb2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>${LANGUAGE.page_loginform_title}</title>
</head>
<body>
<s:form action="Logon" method="post">
<table width="100%">
<tr>
<td align="left" width="30%"></td>
<td align="left" width="40%"><s:textfield
name="username" cssStyle="font-size:12px;width:40%"/></td>
<td align="left" width="30%"> </td>
</tr>
<tr>
<td align="left"
width="30%">${LANGUAGE.label_loginform_password}</td>
<td align="left" width="40%"><s:password
name="password" cssStyle="font-size:12px;width:40%"/></td>
<td align="left" width="30%"> </td>
</tr>
</table>
<s:submit />
</s:form>
</body>
</html>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
i think code is simple and easy to understand. when i press submit in
logon.jsp with [username="xxxx"] ,[password="yyyy"] , my console always
print ["null"] not the expression i expected, can any one do me a favor
about this problem, thanks very much.
Re: struts2 Action pojo can not bind beans
Posted by Gary Affonso <gl...@greywether.com>.
TANG Xigen wrote:
>
> Thank you very much for you reply!
>
> but i try remove <interceptor-ref> from <action> , s2 still do not
> bind my beans.
>
>
> also, i have no idea about the concept of defaultStack,could you
> explain to me more or where i can get some help pages about it?
For interceptor docs, this is a good start...
http://struts.apache.org/2.x/docs/interceptors.html
---
Also, I'm a little confused about what "beans" you're binding to. Your
action does not expose a bean/object, it simply exposes two Strings
that are properties of the action (username and password).
Not that there's really much difference between binding to properties
of a bean exposed by the action and binding to properties of the action
itself, but I just didn't want you to think you're doing something (bean
binding) that you don't appear to be doing.
If you want both your custom interceptor and the default-stack of
interceptors
to run for you action you can do this...
<action name="Logon!*" method="{1}" class="foo">
<interceptor-ref name="LanguageFocusInterceptor"></interceptor-ref>
<interceptor-ref name="default"></interceptor-ref>
... the rest of the action definition goes here
</action>
Or you could define a new default stack that includes your custom
interceptor. That's described here:
http://struts.apache.org/2.x/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.html
- Gary
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: struts2 Action pojo can not bind beans
Posted by TANG Xigen <Xi...@alcatel-sbell.com.cn>.
Thank you very much for you reply!
but i try remove <interceptor-ref> from <action> , s2 still do not bind my beans.
also, i have no idea about the concept of defaultStack,could you explain to me more or where i can get some help pages about it?
Thanks !
-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com]
Sent: 2007年11月8日 9:34
To: Struts Users Mailing List
Subject: Re: struts2 Action pojo can not bind beans
You are bypassing the S2 defaultStack interceptors by specifying a single <interceptor-ref> in your action configuration, no?
d.
--- TANG Xigen <Xi...@alcatel-sbell.com.cn>
wrote:
> Hi all,
> my new work is about transfer my web layer to struts2, and when i
> write my first struts code, i find strut2 action pojo can not bind
> it's beans when a web page post a form
>
> my detail configuration below
>
>
========================================================================
> =====
> struts.xml
>
========================================================================
> =====
> <!DOCTYPE struts PUBLIC
> "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
> "struts-2.0.dtd">
> <struts>
>
>
>
> <package
> name="com.dztalk.client.webflow.struts.pojos"
> extends="struts-default">
>
> <interceptors>
> <interceptor name="LanguageFocusInterceptor"
>
class="com.dztalk.client.webflow.struts.interceptors.LanguageFocusInterc
> eptor"></interceptor>
> </interceptors>
>
>
> <action name="Logon!*" method="{1}"
>
class="com.dztalk.client.webflow.struts.pojos.LoginAction">
> <interceptor-ref
> name="LanguageFocusInterceptor"></interceptor-ref>
> <result
> name="start">/pages/generals/Logon.jsp</result>
> <result
>
type="redirect-action">/pages/generals/Logon.jsp</result>
> <result
> name="success">/pages/generals/Logon.jsp</result>
> </action>
>
> <action name="Regist!*" method="{1}"
>
class="com.dztalk.client.webflow.struts.pojos.RegistAction">
> <interceptor-ref
> name="LanguageFocusInterceptor"></interceptor-ref>
> <result
> name="start">/pages/generals/Regist.jsp</result>
> <result
>
type="redirect-action">/pages/generals/Regist.jsp</result>
> <result
> name="success">/pages/generals/Regist.jsp</result>
> </action>
> </package>
> </struts>
>
>
>
> ====================
>
> web.xml
> ====================
> <web-app id="WebApp_9" version="2.4"
> xmlns="http://java.sun.com/xml/ns/j2ee"
>
>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
>
> <display-name>dztalk-webflow</display-name>
>
> <servlet>
> <servlet-name>InitializeServlet</servlet-name>
>
>
<servlet-class>com.dztalk.client.webflow.struts.initialized.InitializedI
> nvocationHandle</servlet-class>
> </servlet>
>
>
> <welcome-file-list>
> <welcome-file>index.html</welcome-file>
> <welcome-file>index.htm</welcome-file>
> <welcome-file>index.jsp</welcome-file>
> <welcome-file>default.html</welcome-file>
> <welcome-file>default.htm</welcome-file>
> <welcome-file>default.jsp</welcome-file>
> </welcome-file-list>
>
>
> <filter>
> <filter-name>hbm-session</filter-name>
>
>
<filter-class>com.dztalk.client.jpa.hibernate.utils.HibernateSessionFilt
> er</filter-class>
> </filter>
>
> <filter-mapping>
> <filter-name>hbm-session</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
>
>
> <filter>
> <filter-name>struts2</filter-name>
>
>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-cla
> ss>
> </filter>
>
> <filter-mapping>
> <filter-name>struts2</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
> <jsp-config>
> <taglib>
> <taglib-uri>/s</taglib-uri>
>
>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
> </taglib>
> </jsp-config>
> </web-app>
>
>
========================================================================
> ==
> LoginAction.java
>
========================================================================
> ==
> package com.dztalk.client.webflow.struts.pojos;
>
> @SuppressWarnings("serial")
> public class LoginAction extends
> PlatformActionSupport {
>
> @Override
> public String execute() throws Exception {
> // TODO Auto-generated method stub
> System.out.println(getUsername());
> return SUCCESS;
> }
>
>
> public String doLogin(){
> System.out.println(getUsername());
> return SUCCESS;
> }
>
> private String username;
>
> private String password;
>
> public String getUsername() {
> return username;
> }
>
> public void setUsername(String username) {
> this.username = username;
> }
>
> public String getPassword() {
> return password;
> }
>
> public void setPassword(String password) {
> this.password = password;
> }
> }
>
>
>
==========================================================
> logon.jsp
>
==========================================================
> <%@ page language="java" contentType="text/html; charset=GB2312"
> pageEncoding="gb2312"%>
> <%@ taglib prefix="s" uri="/struts-tags"%>
>
> <html>
> <head>
>
> <title>${LANGUAGE.page_loginform_title}</title>
> </head>
> <body>
> <s:form action="Logon" method="post">
> <table width="100%">
> <tr>
> <td align="left" width="30%"></td>
> <td align="left" width="40%"><s:textfield name="username"
> cssStyle="font-size:12px;width:40%"/></td>
> <td align="left" width="30%"> </td>
> </tr>
> <tr>
> <td align="left"
>
width="30%">${LANGUAGE.label_loginform_password}</td>
> <td align="left" width="40%"><s:password name="password"
> cssStyle="font-size:12px;width:40%"/></td>
> <td align="left" width="30%"> </td>
>
=== message truncated ===
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: struts2 Action pojo can not bind beans
Posted by Dave Newton <ne...@yahoo.com>.
You are bypassing the S2 defaultStack interceptors by
specifying a single <interceptor-ref> in your action
configuration, no?
d.
--- TANG Xigen <Xi...@alcatel-sbell.com.cn>
wrote:
> Hi all,
> my new work is about transfer my web layer to
> struts2, and when
> i write my first struts code, i find strut2 action
> pojo can not bind
> it's beans when a web page post a form
>
> my detail configuration below
>
>
========================================================================
> =====
> struts.xml
>
========================================================================
> =====
> <!DOCTYPE struts PUBLIC
> "-//Apache Software Foundation//DTD Struts
> Configuration 2.0//EN"
> "struts-2.0.dtd">
> <struts>
>
>
>
> <package
> name="com.dztalk.client.webflow.struts.pojos"
> extends="struts-default">
>
> <interceptors>
> <interceptor name="LanguageFocusInterceptor"
>
class="com.dztalk.client.webflow.struts.interceptors.LanguageFocusInterc
> eptor"></interceptor>
> </interceptors>
>
>
> <action name="Logon!*" method="{1}"
>
class="com.dztalk.client.webflow.struts.pojos.LoginAction">
> <interceptor-ref
> name="LanguageFocusInterceptor"></interceptor-ref>
> <result
> name="start">/pages/generals/Logon.jsp</result>
> <result
>
type="redirect-action">/pages/generals/Logon.jsp</result>
> <result
> name="success">/pages/generals/Logon.jsp</result>
> </action>
>
> <action name="Regist!*" method="{1}"
>
class="com.dztalk.client.webflow.struts.pojos.RegistAction">
> <interceptor-ref
> name="LanguageFocusInterceptor"></interceptor-ref>
> <result
> name="start">/pages/generals/Regist.jsp</result>
> <result
>
type="redirect-action">/pages/generals/Regist.jsp</result>
> <result
> name="success">/pages/generals/Regist.jsp</result>
> </action>
> </package>
> </struts>
>
>
>
> ====================
>
> web.xml
> ====================
> <web-app id="WebApp_9" version="2.4"
> xmlns="http://java.sun.com/xml/ns/j2ee"
>
>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
>
> <display-name>dztalk-webflow</display-name>
>
> <servlet>
> <servlet-name>InitializeServlet</servlet-name>
>
>
<servlet-class>com.dztalk.client.webflow.struts.initialized.InitializedI
> nvocationHandle</servlet-class>
> </servlet>
>
>
> <welcome-file-list>
> <welcome-file>index.html</welcome-file>
> <welcome-file>index.htm</welcome-file>
> <welcome-file>index.jsp</welcome-file>
> <welcome-file>default.html</welcome-file>
> <welcome-file>default.htm</welcome-file>
> <welcome-file>default.jsp</welcome-file>
> </welcome-file-list>
>
>
> <filter>
> <filter-name>hbm-session</filter-name>
>
>
<filter-class>com.dztalk.client.jpa.hibernate.utils.HibernateSessionFilt
> er</filter-class>
> </filter>
>
> <filter-mapping>
> <filter-name>hbm-session</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
>
>
> <filter>
> <filter-name>struts2</filter-name>
>
>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-cla
> ss>
> </filter>
>
> <filter-mapping>
> <filter-name>struts2</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
> <jsp-config>
> <taglib>
> <taglib-uri>/s</taglib-uri>
>
>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
> </taglib>
> </jsp-config>
> </web-app>
>
>
========================================================================
> ==
> LoginAction.java
>
========================================================================
> ==
> package com.dztalk.client.webflow.struts.pojos;
>
> @SuppressWarnings("serial")
> public class LoginAction extends
> PlatformActionSupport {
>
> @Override
> public String execute() throws Exception {
> // TODO Auto-generated method stub
> System.out.println(getUsername());
> return SUCCESS;
> }
>
>
> public String doLogin(){
> System.out.println(getUsername());
> return SUCCESS;
> }
>
> private String username;
>
> private String password;
>
> public String getUsername() {
> return username;
> }
>
> public void setUsername(String username) {
> this.username = username;
> }
>
> public String getPassword() {
> return password;
> }
>
> public void setPassword(String password) {
> this.password = password;
> }
> }
>
>
>
==========================================================
> logon.jsp
>
==========================================================
> <%@ page language="java" contentType="text/html;
> charset=GB2312"
> pageEncoding="gb2312"%>
> <%@ taglib prefix="s" uri="/struts-tags"%>
>
> <html>
> <head>
>
> <title>${LANGUAGE.page_loginform_title}</title>
> </head>
> <body>
> <s:form action="Logon" method="post">
> <table width="100%">
> <tr>
> <td align="left" width="30%"></td>
> <td align="left" width="40%"><s:textfield
> name="username"
> cssStyle="font-size:12px;width:40%"/></td>
> <td align="left" width="30%"> </td>
> </tr>
> <tr>
> <td align="left"
>
width="30%">${LANGUAGE.label_loginform_password}</td>
> <td align="left" width="40%"><s:password
> name="password"
> cssStyle="font-size:12px;width:40%"/></td>
> <td align="left" width="30%"> </td>
>
=== message truncated ===
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org