STRUTS2 Fourth day

Source: Internet
Author: User

Three. Sub-module configuration method

<inclue file= "" ></include>


Xml


Cheliang.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache software foundation//dtd Struts Configuration 2.0//en"
"Http://struts.apache.org/dtds/struts-2.0.dtd" >

<struts>

<package name= "Cheliang" namespace= "/cheliang" extends= "Struts-default" >
<action name= "Cheliang" class= "Com.java1234.action.CheLiangAction" >
<result name= "Success" >${pageContext.request.contextPath}/success.jsp</result>
</action>

</package>

</struts>

Zichan.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache software foundation//dtd Struts Configuration 2.0//en"
"Http://struts.apache.org/dtds/struts-2.0.dtd" >

<struts>

<package name= "Zichan" namespace= "/zichan" extends= "Struts-default" >
<action name= "Zichan" class= "Com.java1234.action.ZiChanAction" >
<result name= "Success" >${pageContext.request.contextPath}/success.jsp</result>
</action>

</package>

</struts>

Struts.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache software foundation//dtd Struts Configuration 2.0//en"
"Http://struts.apache.org/dtds/struts-2.0.dtd" >

<struts>

<include file= "Cheliang.xml" ></include>
<include file= "Zichan.xml" ></include>

</struts>

Action


Cheliangaction.java

Package com.java1234.action;

Import Com.opensymphony.xwork2.ActionSupport;

public class Cheliangaction extends actionsupport{

/**
*
*/
Private static final long serialversionuid = 1L;

@Override
Public String Execute () throws Exception {
System.out.println ("default method for executing cheliangaction action");
return SUCCESS;
}
}

Zichanaction.java

Package com.java1234.action;

Import Com.opensymphony.xwork2.ActionSupport;

public class Zichanaction extends actionsupport{

/**
*
*/
Private static final long serialversionuid = 1L;

@Override
Public String Execute () throws Exception {
System.out.println ("default method for executing zichanaction action");
return SUCCESS;
}

}

Four. Use a wildcard character


Action


Gradeaction.java

Package com.java1234.action;

Import Com.opensymphony.xwork2.ActionSupport;

public class Gradeaction extends actionsupport{

private String name;


Public String GetName () {
return name;
}

public void SetName (String name) {
THIS.name = name;
}


Public String list () throws exception{
SYSTEM.OUT.PRINTLN ("Class lookup");
Name= "Class Search";
return SUCCESS;
}

Public String Add () throws exception{
SYSTEM.OUT.PRINTLN ("class add");
Name= "class add";
return SUCCESS;
}

Public String Update () throws exception{
SYSTEM.OUT.PRINTLN ("Class modification");
Name= "Class modification";
return SUCCESS;
}

Public String Delete () throws exception{
SYSTEM.OUT.PRINTLN ("class delete");
Name= "Class deletion";
return SUCCESS;
}

}

Studentaction.java

Package com.java1234.action;

Import Com.opensymphony.xwork2.ActionSupport;

public class Studentaction extends actionsupport{

private String name;

Public String GetName () {
return name;
}

public void SetName (String name) {
THIS.name = name;
}

Public String list () throws exception{
System.out.println ("Student Search");
Name= "Student Search";
return SUCCESS;
}

Public String Add () throws exception{
SYSTEM.OUT.PRINTLN ("Student Add");
Name= "Student Add";
return SUCCESS;
}

Public String Update () throws exception{
SYSTEM.OUT.PRINTLN ("Student modification");
Name= "Student Modification";
return SUCCESS;
}

Public String Delete () throws exception{
SYSTEM.OUT.PRINTLN ("student Delete");
Name= "Student deletion";
return SUCCESS;
}
}

Xml



<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE Struts Public
"-//apache software foundation//dtd Struts Configuration 2.0//en"
"Http://struts.apache.org/dtds/struts-2.0.dtd" >

<struts>

<constant name= "Struts.enable.DynamicMethodInvocation" value= "true"/>

<package name= "Manage" namespace= "/" extends= "Struts-default" >

<!--<action name= "student_*" class= "com.java1234.action.StudentAction" method= "{1}" >
<result name= "Success" >success.jsp</result>
</action>

<action name= "grade_*" class= "com.java1234.action.GradeAction" method= "{1}" >
<result name= "Success" >success.jsp</result>
</action>
      
<!--<action name= "*_*" class= "com.java1234.action. {1} Action "method=" {2} ">
<result name= "Success" >success.jsp</result>
</action>

<action name= "Student" class= "com.java1234.action.StudentAction" >
<result name= "Success" >success.jsp</result>
</action>

<action name= "Grade" class= "Com.java1234.action.GradeAction" >
<result name= "Success" >success.jsp</result>
</action>

</package>

</struts>

Section sixth. Dynamic Method invocation

<constant name= "Struts.enable.DynamicMethodInvocation" value= "true"/>


XML file


<%@ 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" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
<a href= "student_list" target= "_blank" > Student Information Enquiry </a>&nbsp;
<a href= "Student_add" target= "_blank" > Student Information Add </a>&nbsp;
<a href= "student_update" target= "_blank" > Student Information Modification </a>&nbsp;
<a href= "Student_delete" target= "_blank" > Student Information Removal </a>&nbsp;
<br/><br/>
<a href= "grade_list" target= "_blank" > class information Query </a>&nbsp;
<a href= "Grade_add" target= "_blank" > class info Add </a>&nbsp;
<a href= "grade_update" target= "_blank" > class information Modification </a>&nbsp;
<a href= "Grade_delete" target= "_blank" > class info Delete </a>&nbsp;<br/>
<a href= "student!list" target= "_blank" > Student Information Enquiry </a>&nbsp;
<a href= "Student!add" target= "_blank" > Student Information Add </a>&nbsp;
<a href= "student!update" target= "_blank" > Student Information Modification </a>&nbsp;
<a href= "Student!delete" target= "_blank" > Student Information Removal </a>&nbsp;
<br/><br/>
<a href= "grade!list" target= "_blank" > class information Query </a>&nbsp;
<a href= "Grade!add" target= "_blank" > class info Add </a>&nbsp;
<a href= "grade!update" target= "_blank" > class information Modification </a>&nbsp;
<a href= "Grade!delete" target= "_blank" > class info Delete </a>&nbsp;<br/>
</body>



Section Seventh: Action life cycle


Action


Helloaction

public class Helloaction extends actionsupport{

/**
*
*/
Private static final long serialversionuid = 1L;

Public Helloaction () {
System.out.println (this);
}

@Override
Public String Execute () throws Exception {
TODO auto-generated Method Stub
return SUCCESS;
}

}

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= "Manage" namespace= "/" extends= "Struts-default" >

<action name= "Hello" class= "com.java1234.action.HelloAction" >
<result name= "Success" >success.jsp</result>
</action>
</package>

</struts>

Note: An action instance is created for each request, and spring defaults to a singleton


STRUTS2 Fourth day

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.