webwork+velocity Consolidation Case

Source: Internet
Author: User
Step 1:

Pom.xml

<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        < dependency>
            <groupId>opensymphony</groupId>
            <artifactid>webwork</artifactid >
            <version>2.2.5</version>
        </dependency>
        <dependency>
            <groupid >org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version >1.7</version>
        </dependency>
        <dependency>
            <groupId> org.apache.velocity</groupid>
            <artifactId>velocity-tools</artifactId>
            <version >2.0</version>
        </dependency>
Step 2:

Web.xml

<! DOCTYPE Web-app Public "-//sun Microsystems, INC.//DTD Web Application 2.3//en" "Http://java.sun.com/dtd/web-app_2_3.dt D "> <web-app> <display-name>archetype Created Web application</display-name> <servlet&gt
        ; <servlet-name>webwork</servlet-name> <servlet-class>
        Com.opensymphony.webwork.dispatcher.servletdispatcher</servlet-class> </servlet> <servlet> <servlet-name>velocity</servlet-name> <servlet-class>com.opensymphony.webwork.views.velocity . 

    Webworkvelocityservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>webwork</servlet-name> <url-pattern>*.action </url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>velocity</se Rvlet-name> <url-pattern>*.vm</urL-pattern> </servlet-mapping> </web-app>
 
Step 3:

Index.vm

<! DOCTYPE html>
Step 4:

Useraction.java

Package com.wuk.action;

Import com.opensymphony.xwork.Action;
Import Com.wuk.entity.User;

public class Useraction implements action{

    Private user user;
    private String message;
    @Override public
    String execute () throws Exception {

        message=user.getname () + "Welcome";

        return SUCCESS;
    }

    Public User GetUser () {return
        user;
    }

    public void SetUser (user user) {
        this.user = user
    }

    Public String GetMessage () {return message
        ;
    }

    public void Setmessage (String message) {
        this.message = message;
    }


}
Step 5:

Xwork.xml

<! DOCTYPE xwork Public "-//opensymphony group//xwork 1.0//en" "Http://www.opensymphony.com/xwork/xwork-1.0.dtd" >
<xwork>
    <include file= "Webwork-default.xml"/>

    <package name= "Default" extends= " Webwork-default ">

        <!--Action's name parameter is a URL such as Http://localhost/welcome.action-->
        <action name=" Welcome "class=" "Com.wuk.action.UserAction" >
            <result name= "Success" type= "Velocity" >

                 <param Name= "Location" >/result.vm</param>
            </result>

            <!--Interceptor-ref defines the interceptor that this action uses-- >
            <interceptor-ref name= "params"/>
        </action>
    </package>
</xwork>
Step 6:

Result.vm

<! DOCTYPE html>

Note that the velocity syntax is used here.

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.