When writing a SSH2 project, in addition to using the <s:form> form tag to jump and pass parameters to the action class, it is much more time to use the <s:a action= "xxx.action" > this link tag to jump, at this time, It is necessary to pass the required parameters. In addition, when you get the data from the action class on the JSP page, you also need to pay attention to how the property gets.
Previously here, due to my carelessness, led to no corresponding data display on the JSP page. Originally thought that is not read from the database to the data, so I from the persistence layer, DAO layer, service Layer, action class check several times, modified multiple code, the result is found, is the last JSP did not show the data. Therefore, it is necessary to make a record, in the future to avoid such situations happen again.
(1) JSP page Get property value
Abcaction.java-xxx.jsp
There are properties list<article> articles in the Abcaction.java class, and there are corresponding gettersetter methods.
On the xxx.jsp page, through <s:iterator> output
When the id attribute is in the <s:iterator> tag, add # to the output attribute value.
<S:iteratorvalue= "articles"ID= "article"Status= "St"><!--has id attribute - <S:propertyvalue= "#article. Title"/> <!--You need to add a # to output the attributes in article -</S:iterator><S:iteratorvalue= "articles"Status= "St"><!--No id attribute - <S:propertyvalue= "title"/> <!--direct output of properties in article -</S:iterator>
If you do not need to use the <s:iterator> label, only <s:property value= ""/>
1) Get the property in the action class, <s:property value= "Article.title"/>, do not add #, otherwise you cannot get the property value
2) Gets the properties of the non-action class, <s:property value= "#session. User"/> # must be added, otherwise the property value cannot be obtained
(2) jsp page pass parameters
xxx.jsp -- Abcaction.java
1) through <s:param> tags
You need to configure the abc.action in the Struts.xml file
<action= "abc.action"> jump to Abc.action and pass in ArticleID parameter <name= "ArticleID"><value = "#article. Id"/></s:param></s:a >
Of course Abcaction.java must be articleid by the attributes and Gettersetter methods.
2) pass through the href attribute ch
<href= "Abc.action?articleid=<s:property value= ' #article. Id ' >'> jump to Abcaction.java and assign value to ArticleID property </s:a>
JSP pages, using Struts2 tags, to pass and get parameters in the action class, considerations. <s:a-ACTION><S:ITERATOR><S:PARAM>OGNL expression