import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class logintest extends ActionSupport { private String name; private String password; 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 execute() throws Exception { ServletActionContext.getRequest().setAttribute("name", name); ServletActionContext.getRequest().setAttribute("password", password); return SUCCESS; } }
红色的地方出错了,老是报:Access restriction: The method setAttribute(String, Object) from the type ServletRequest is not accessible due to restriction on required library D:\应用\eclipse\jre\lib\ext\servlet-api.jar,怎么解决?
你少包了,楼上正解
jar包少了servlet这个包