日期:2014-05-20  浏览次数:20685 次

请教关于sturts里getAttribute和setAttribute的使用
我用   JBuilder   2005   写的一个简单的struts程序,在登陆界面输入用户名密码,在登陆成功页面显示输入的用户名,用getAttribute和getParameter方法怎么写?

这是JSP页面代码
<%
se   v=(se)request.getAttribute( "name ");
%>
<html>
<head>
<title>
jsp2
</title>
</head>
<body   bgcolor= "#ffffff ">
<h1>
欢迎 <%=v.getName   %> 登陆
</h1>
</body>
</html>

这是Action代码
public   class   loginAction   extends   Action   {
        public   ActionForward   execute(ActionMapping   actionMapping,
                                                                  ActionForm   actionForm,
                                                                  HttpServletRequest   servletRequest,
                                                                  HttpServletResponse   servletResponse)   {
                loginActionForm   loginActionForm   =   (loginActionForm)   actionForm;
                String   name   =   loginActionForm.getName();
                String   pwd   =   loginActionForm.getPwd();
                if   (name.equals( "123 ")   &&   pwd.equals( "123 "))
                {
                        return   actionMapping.findForward( "mian ");
                }

                return   actionMapping.findForward( " ");
        }
}
setAttribute方法在Action里要怎么写才能在JSP页面里读到输入的用户名?

------解决方案--------------------
if (name.equals( "123 ") && pwd.equals( "123 "))
{
Se se = new Se();
se.setName(name);
request.setAttribute( "name ",se);
return actionMapping.findForward( "mian ");
}