1. for installation and configuration of Eclipse, MySQL, and Apache Tomcat, see the previous articles.
Create a dynamic web project named oatest
2. struts2 Configuration
Download the complete package required by struts2, copy the following files to the lib directory of the corresponding web project webcontent/WEB-INF/lib of Eclipse:
1) xwork-core-2) struts2-core-3) ognl-4) freemarker-5) commons-io- 6)commons-fileupload-
7)javassist-
8) commons-lang3-
3. modify web. XML in struts2Add filter to modify web. xml. The final configuration file is as follows:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts><constant name="struts.i18n.encoding" value="GBK"></constant><package name="default" extends="struts-default"><action name="loginAction" class="com.oa.action.LoginAction"><result name="success">welcome.jsp</result><result name="error">err.jsp</result></action></package></struts>
4. Define the form's JSP page
<% @ Page Language = "Java" contenttype = "text/html; charset = GBK "pageencoding =" UTF-8 "%> <% @ taglib prefix =" C "uri ="/Struts-tags "%> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> 5. Define the interception class com. OA. Action. loginaction
Note that the package isCom. 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;}}