STRUTS2: Implementing the C (servlet) layer and V (JSP) layer
To add struts to your project:
1: Click on Project Right click to select MyEclipse
2: Select Add Struts capadilities
3: Select 2.1
1. Build a package in SRC, create a new class in the package and inherit the Actionsupport interface, and rewrite the Execute () method inside.
The code is: public class Actmnt extends Actionsupport {
private String name;
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
@Override
Public String Execute () throws Exception {
TODO auto-generated Method Stub
return "name";
}
}
2. Create a new action in Struts.xml
<package name= "Default" extends= "Struts-default" >
<action name= "Userlogin" class= "Org.vo.Actmnt" >
<result name= "Name" >/stuer/bean.jsp</result>
</action>
</package>
3. Edit the display interface in the JSP
<s:bean name= "org.vo.Actmnt" id= "Stu" >
The:<br> can be output directly inside the bean tag
<s:param name= "name" > Zhou Ho Jun </s:param>
(1) The first method of assignment:
<s:property value= "Name"/><br>
(2) The second method of assignment:
<!--This method assigns a value string to the parameter must be quoted--and
<s:param name= "name" value= "' Zhou Ho Jun '" ></s:param>
<s:property value= "Name"/>
</s:bean>
<br>
Take the ID value outside the bean label:
<s:property value= "#stu. Name"/>
4. Deploy the project and enter: Http://localhost:8080/classwork/userlogin.action run in the browser.
The result is:
Based on Struts2 value (143 Roccaipo)