早教吧 育儿知识 作业答案 考试题库 百科 知识分享

struts标签获得不了jsp页面的值(username,password打印出来都是null)LoginAction类:packagecom.actions;importcom.opensymphony.xwork2.ActionSupport;publicclassLoginActionextendsActionSupport{Stringusername;Stringpassword;publ

题目详情
struts标签获得不了jsp页面的值(username,password打印出来都是null)
LoginAction类:
package com.actions;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
String username;
String password;
public String getUsername(){
return username;
}
public void setUsername(){
this.username = username;
}
public String getPassword(){
System.out.print(password);
return password;
}
public void setPassword(){
this.password = password;
}
public String execute() throws Exception{
System.out.print("xax" + getUsername() + " "+getPassword());
return SUCCESS;
}
}
JSP:
Login
//中间一堆meta啥的去掉的,空间不够

还未注册?点击注册



web.xml:
login.jsp
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
struts.xml
/login_success.jsp
▼优质解答
答案和解析
我试过你的代码,发现错误在于你的LoginAction代码,这两个set方法没写对,应该有参数的,否则没法赋值的.public void setUsername(String username){this.username = username;}public void setPassword(String passwor...