Pages

Wednesday, 11 September 2013

Struts 2 Store User Input Details In Separate Java Bean

Let us see how to store user input details in the separate bean, actually up to now we stored user input values in Action class by writing setters and getter methods, but there is a chance to store in separate bean class, will see how.

Advantage Of Taking Separate Java Bean

Is to get re-usability, means if more than one Action class need to use the same properties then same properties we can use from this java bean it self with out wiring setters and getters in both Action classes.
Any ways files required…
  • success.jsp
  • error.jsp
  • index.jsp
  • LogingEx.java [ in java4s package ]
  • MyBean.java [ in java4s package ]
  • web.xml [ in web-inf ]
  • struts.xml [ in web-inf/classes folder ]

index.jsp

success.jsp

error.jsp

LogingEx.java

MyBean.java

web.xml

struts.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?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="struts-default.xml"/>
<package name="a" extends="struts-default">
<action name="verify" class="java4s.LogingEx">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>

No comments:

Post a Comment