1.
错误信息:
Unable to load configuration. - bean -
jar:file:/D:/eclipseworkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/struts2/WEB-INF/lib/struts2-
core-2.1.6.jar!/struts-default.xml:46:178
解决办法:
加入两个jar包(commons-io.jar commons-fileupload.jar)
2.
错误信息:
2009-08-06 14:23:37,796 WARN [org.apache.struts2.components.ServletUrlRenderer] - No configuration found for the specified
action: 'login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
2009-08-06 14:23:40,109 WARN [org.apache.struts2.components.ServletUrlRenderer] - No configuration found for the specified
action: 'login' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
2009-08-06 14:23:42,828 WARN [org.apache.struts2.dispatcher.Dispatcher] - Could not find action or result
There is no Action mapped for namespace / and action name login. - [unknown location]
解决办法:
将struts.xml文件放在WEB-INF/classes目录下
补充:
struts.xml
<!-- package namespace属性值默认为"" -->
<package name="humanly identity" namespace="/example" extends="struts-default">
<action name="login" class="cn.devon.action.LoginAction" method="loginCheck">
<!-- result 默认name属性值为success -->
<result name="loginSuccess">/welcome.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>
jsp页面
<!-- index.jsp -->
<%@ taglib uri="struts-tags" prefix="s"%>
<!-- s:from namespace属性必须与action所对应的package中的namespace属性值一致 -->
<font style="color:red">
<s:property value="message"/>
</font>
<s:form action="login" namespace="/example">
<s:textfield label="User name" name="member.name"/>
<s:textfield label="Password" name="member.password"/>
<s:submit value="Login"/> <s:reset value="Reset"/>
</s:form>
<!-- welcome.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="struts-tags" prefix="s"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>welcome you !</title>
</head>
<body>
Welcome ${member.name}, your password is ${member.password}.
</body>
</html>
cn.devon.action.LoginAction类
package cn.devon.action;
import org.apache.struts2.ServletActionContext;
import cn.devon.entity.Member;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private String message;
private Member member;
public Member getMember() {
return member;
}
public void setMember(Member member) {
this.member = member;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String login(){
System.out.println("------login--------");
if("1".equals(member.getName()) && "1".equals(member.getPassword())){
ServletActionContext.getRequest().setAttribute("member", member);
return "loginSuccess";
}
message = "Username or password wrong.";
return "input";
}
}
cn.devon.entity.Member类
package cn.devon.entity;
public class Member {
private int id;
private String name;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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;
}
}