Compile the struct2 demo in eclipse

Source: Internet
Author: User
Tags apache tomcat

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 struts2

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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.