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.