Struts2 (1), Struts2 (

Source: Internet
Author: User

Struts2 (1), Struts2 (
I. Struts

Http://struts.apache.org/download.cgi

2. Import packages, configure Web. xml and struts. xml

Find some packages in the downloaded package.

Struts2-2.3.4.1-all \ struts-2.3.4.1 \ apps \ struts2-blank \ WEB-INF \ lib

Add

 <filter>        <filter-name>struts2</filter-name>        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>    </filter>    <filter-mapping>        <filter-name>struts2</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>  

Struts. xml can find the sample changes under struts2-2.3.4.1-all \ struts-2.3.4.1 \ apps \ struts2-blank \ WEB-INF \ classes

<?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><!--     <constant name="struts.enable.DynamicMethodInvocation" value="false" />    <constant name="struts.devMode" value="false" />    <package name="default" namespace="/" extends="struts-default">        <default-action-ref name="index" />        <global-results>            <result name="error">/error.jsp</result>        </global-results>        <global-exception-mappings>            <exception-mapping exception="java.lang.Exception" result="error"/>        </global-exception-mappings>        <action name="index">            <result type="redirectAction">                <param name="actionName">HelloWorld</param>                <param name="namespace">/example</param>            </result>        </action>    </package>    <include file="example.xml"/>    class="com.opensymphony.xwork2.ActionSupport" -->    <!-- Add packages here -->    <constant name="struts.devMode" value="true" /><package name="default" namespace="/" extends="struts-default">                <action name="hello" class="com.pb.web.action.HelloAction3">            <result>               /helloStruts.jsp            </result>        </action>    </package></struts>
Iii. Implementation

Action

 

Package com. pb. web. action; import com. opensymphony. xwork2.ActionSupport;/** the third type inherits the ActionSupport class. It is the implementation class of Action */public class HelloAction3 extends ActionSupport {/*****/private static final long serialVersionUID = 1L; @ Override public String execute () throws Exception {// TODO Auto-generated method stub return "success ";}}

 

Page

helloStruts.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Enter http: // localhost: 8080/StrutsDemo1/hello. action in the address bar.

You can use hello. action to access the helloStruts. jsp page.

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.