初学Struts2.0笔记

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





/welcome.jsp
/index.jsp




jsp页面


<%@ taglib uri="struts-tags" prefix="s"%>













<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="struts-tags" prefix="s"%>



welcome you !


Welcome ${member.name}, your password is ${member.password}.




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;
}
}

你可能感兴趣的:(Struts,Java,JSP,Apache,Eclipse)