Struts2.0 页码传值到Action的问题

我的Action总是取不到页面传的值是为什么?
我的web.xml配置如下:
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>

<display-name>PGProject</display-name>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>


sitemesh
com.opensymphony.sitemesh.webapp.SiteMeshFilter

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>    

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<listener>
    <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>
</listener>    

 <servlet>
    <servlet-name>sitemesh-freemarker</servlet-name>
    <servlet-class>org.apache.struts2.sitemesh.FreemarkerDecoratorServlet</servlet-class>
    <init-param>
        <param-name>default_encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>sitemesh-freemarker</servlet-name>
    <url-pattern>*.ftl</url-pattern>
</servlet-mapping>   

<welcome-file-list>
    <welcome-file>Login.action</welcome-file>
</welcome-file-list>


[/code]
页面代码如下:
[code="html"]
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>


登录

用户名:
密码:



[/code]
Action代码如下:
[code="java"]
package cn.com.pzhsteel.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import cn.com.pzhsteel.pojo.JUser;
import cn.com.pzhsteel.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport
{

/**
 * 
 */
private static final long serialVersionUID = 1L;
private JUser user;
private UserService myService;
public String execute()throws Exception
{
    System.out.println("fdsafdsafdsafdsafdsaf");
    return SUCCESS;
}
public String checkUser() throws Exception
{
    HttpServletRequest request = ServletActionContext.getRequest();
    String flag=request.getParameter("user.name");
    if(myService == null)
        return "error";
    else
    {
        if(user == null)
        {
            user = new JUser();
            user.setName("test");
            user.setPassword("12345");
        }
        if(myService.isUser(user))
            return "success";
        else
            return "unsuccess";
    }
}

public JUser getUser()
{
    return user;
}

public void setUser(JUser user)
{
    this.user = user;
}

public void setMyService(UserService myService)
{
    this.myService = myService;
}

}
[/code]
POJO类代码如下:
[code="java"]
public class JUser
{
private String name;
private String password;
private String sysId;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getSysId()
{
return sysId;
}
public void setSysId(String sysId)
{
this.sysId = sysId;
}
}
[/code]
Struts2配置如下:
[code="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">

<!-- Some or all of these can be flipped to true for debugging -->
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="false"/>
<constant name="actionPackages" value="cn.com.pzhsteel.action"/>
<package name="default" namespace="/" extends="struts-default">

    <interceptors>
        <interceptor-stack name="crudStack">
          <interceptor-ref name="checkbox" />
            <interceptor-ref name="params" />
            <interceptor-ref name="staticParams" />
            <interceptor-ref name="defaultStack" />
        </interceptor-stack>
    </interceptors>

    <default-action-ref name="Login" />

    <!--global-results>
        <result name="error">/error.jsp</result>
    </global-results-->

    <global-exception-mappings>
        <exception-mapping exception="java.lang.Exception" result="error"/>
    </global-exception-mappings>

    <action name="Login">
        <result>Login.jsp</result>
    </action>
    <action name="userAction" class="userAction" method = "checkUser">
        <result name="success">/Login.jsp</result>
        <result name="unsuccess">/error.jsp</result>
    </action>

</package>

[/code]
可User对象使中获取不到值?为什么呀?????

3个回答

你把
[code="java"]

[/code]
改成
[code="java"] [/code]
再试试。

你先确定,点登陆的时候,有没有进入Action?

public String execute()throws Exception
{
System.out.println("fdsafdsafdsafdsafdsaf");
return SUCCESS;
}
public String checkUser() throws Exception
{}

进Action打印个东西就返回了?checkUser没看到哪里调用啊?
你怎么看到user是空的啊

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问