struts2 action 接收不到值

网页部分:
<body>
<form action="userlogin.action" method="get">
<s:textfield name="s" label="工号"></s:textfield>
<input type="submit" class="login-sub" value="" />
</form>
</body>

struts配置文件:
<?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.i18n.encoding" value="UTF-8"/>
<constant name="struts.serve.static.browserCache" value="false"/>
<constant name="struts.configuration.xml.reload" value="true"/>
<!--<constant name="struts.devMode" value="true" />

--><constant name="struts.objectFactory" value="spring" />

<package name="person" namespace="/" extends="struts-default">
<global-results>
<result name="error">/error.jsp</result>
</global-results>
<action name="userlogin" class="com.jboa.web.action.EmployeeServiceAction" method="Login">
<result name="success">list.jsp</result>
</action>
<action name="book_list" class="booksAction" method="findAll">
<result>/book_list.jsp</result>
</action>

<action name="book_add" class="booksAction" method="save">
<result>/book_add_success.jsp</result>
</action>

</package>

web配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>

<!-- 对Spring容器进行实例化 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
spring的配置就不用写了吧..
EmployeeServiceAction的配置:
private String s;
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
/**
* 用户登陆
* @return
*/
public String Login(){
//如果提交的不为空,则开始进行登陆验证,如果密码正确,保存到session中,如果登陆失败则返回失败页面
// if(EmpLoyess!=null){
// BaseS = (BaseService) new EmployeeServiceAction();
// Employee emp = BaseS.userLogin(EmpLoyess);
// if(emp!=null){
// session.put("user", emp);
// return SUCCESS;
// }else{
// return INPUT;
// }
// }else{
// return INPUT;
// }

System.out.println(s);
return INPUT;
}

EmpLoyess也是接收不到值所以才新建了个String s来测试 结果也不行
调用了action里的方法但是接不到传过来的值
问题找到了 因为java类中接受值的首字母大写的原因导致收不到值

第1个回答  2011-10-04
用火狐的firebug看一下请求地址是否正确,或是重启下服务器再试试
第2个回答  2011-10-03
怎么感觉还是青鸟的,你都写了objectFactory是spring,为什么还要直接写进去com.jboa.web.action.EmployeeServiceAction。追问

别人写的底层 现在给我做实现 都愁死我了. 那段已经删了 但不知道为什么action里就是空 能调用 但是值是空的

追答

userlogin!Login.action 把提交的action改成这个。另外吧method=get去掉试试。

本回答被提问者和网友采纳
第3个回答  2011-10-04
没报错?
你的URL好像不对。
相似回答