读书人

请问关于sturts里getAttribute和setAt

发布时间: 2012-01-06 22:55:18 作者: rapoo

请教关于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 ");
}

读书人网 >J2SE开发

热点推荐