请教关于在sturts里getAttribute和setAttribute的使用

来源:百度知道 编辑:UC知道 时间:2024/05/03 00:22:33
我用 JBuilder 2005 写的一个简单的struts程序,在登陆界面输入用户名密码,在登陆成功页面显示输入的用户名,用getAttribute和setAttribute方法怎么写?

这是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.equa

action 中request.setAttrebute("name",loginActionForm.getName());
jsp 中 <%=(String)request.getAttribute("name")%>

HttpServletRequest.getAttribute(String attr)

上面是基本的servlet里的方法,

在jsp中,request是隐式的,也就是servlet中的
HttpServletRequest request,对应的是
HttpServletResponse response

你所说的,可以直接在action中的execute方法中:
String name=request.getAttribute("name");
String name=request.getAttribute("password");

多说一句:
基本的servlet和jsp的东西都搞明白,就别折腾struts之类的东东了

把基础弄明白最重要!!!!

action 中request.setAttrebute("name",loginActionForm.getName());
jsp 中 <%=(String)request.getAttribute("name")%>

这答案多简单明了

“xmlspy说得有道理! ”?? 我想问3楼 你懂不?

xmlspy说得有道理!