Friday 5 December 2014

param element


The param element is used to define a variable.

Syntax
<param name="property">value</param>

You can use param element in action, interceptor, result-type elements.

 struts.xml
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <package name="default" extends="struts-default">
            
        <action name="numberCheck" class="NumberCheckAction">
            <param name="blog">https://self-learning-java-tutorial.blogspot.com</param>
            <result name="success">/success.jsp</result>
            <result name="failure">/failure.jsp</result>
        </action>

    </package>
</struts>


<param name="blog">https://self-learning-java-tutorial.blogspot.com</param>

Statement sets the variable blog to the value ‘https://self-learning-java-tutorial.blogspot.com’.

public class NumberCheckAction {
    private int number;
    private String blog;

    public String getBlog() {
        return blog;
    }

    public void setBlog(String blog) {
        this.blog = blog;
        System.out.println("Blog set is " + blog);
    }
    
    private static String SUCCESS = "success";
    private static String FAILURE = "failure";
    private static String ZERO = "zero";

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public String execute(){
        if(getNumber() == 0)
            return ZERO;
        if(getNumber() %2 == 0){
            return SUCCESS;
        }
        else{
            return FAILURE;
        }
    }
}


Run ‘numCheck.html file, you can observe the message like ‘INFO: Blog set is https://self-learning-java-tutorial.blogspot.com’ in server log.

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment