配置好struts2环境后
F LoginActionpackage com.login.action; public class LoginAction { public String checkLogin() { System.out.println("checkLogin"); return "login"; }}F LogoutActionpackage com.login.action; public class LogoutAction { public String checkLogout() { System.out.println("checkLogout"); return "logout"; }}F struts-itcast.xml<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <package name="struts2_login" namespace="/" extends="struts-default"> <action name="*_*" class="com.login.action.{1}Action" method="{2}"> <result name="login">/loginSuc.jsp</result> <result name="logout">/logoutSuc.jsp</result> <result name="error">/Error.jsp</result> </action> </package></struts> F struts.xml<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <include file="struts-default.xml" /> <include file="struts-itcast.xml" /></struts>F Error.jsp<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html><head><title>Error</title></head><body><h1>Error</h1></body></html>F login.jsp<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html> <head> </head> <body> <a href="Login_checkLogin.action">login</a> </body></html>F loginSuc.jsp<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html><head><title>login success</title></head><body><h1>Login Success! </h1></body></html>F logout.jsp <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html><head></head><body> <a href="Logout_checkLogout.action">logout</a></body></html>F logSuc.jsp<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html><head><title>logout success</title></head><body><h1>Logout Success! </h1></body></html> 

原文:http://www.cnblogs.com/jianfengyun/p/3634586.html