eclipse 编写struct2的 demo

1、eclipse,mysql,apache tomcat的安装和配置见前面几篇文章

建一个Dynamic Web Project,取名叫OATest

2、struts2配置

下载struts2需要的的完整包,将其中的以下文件复制到eclipse的对应web工程的WebContent/WEB-INF/lib的lib目录下:

            1)xwork-core-
            2)struts2-core-
            3)ognl-
            4)freemarker-
            5)commons-io-
            6)commons-fileupload-
            7)javassist-
            8)commons-lang3-
3、struts2修改web.xml

     修改web.xml增加过滤器filter,最终配置文件如下所示




	
	
		
			welcome.jsp
			err.jsp
		
	




4、定义表单的JSP页面

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




Insert title here


	
		
		
		
	


5、定义拦截类com.oa.action.LoginAction

注意,包为com.oa.action

package com.oa.action;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	private String username;
	private String password;

	public String execute() {
		if (username.equals("a") && password.equals("a"))
			return SUCCESS;
		return ERROR;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}











你可能感兴趣的:(NOSQL)