Upload
anjanikumar-kilari
View
150
Download
4
Tags:
Embed Size (px)
Citation preview
1 22-Jun spring- By Mr. Varma
--DelegatingActionProxy
==>Spring & Struts
What configuration files are required?
1. web.xml : Servlets entries..2. struts-config.xml : struts entries..3. spring-config.xml : Spring entries [ActionServlet-servlet.xml]..
There are 3 ways are provided by spring to integrate struts & Spring..1. DelegatingActionProxy2. DelegatingRequestProcessor3. ActionSupport
1st Approach : DelegatingActionProxy
Steps To integrate 1. Configure "ContextLoaderPlugIn" in the struts-config.xml to read the spring configuration file...
<plug-inclassName="org.springframework.web.struts.ContextLoaderPlugIn"><set-property property="contextConfigLocation"
value="/WEB-INF/ActionServlet-servlet.xml" /></plug-in>
Note : In the web.xml
<servlet-name>ActionServlet</servlet-name><servlet-class>
org.apache.struts.action.ActionServlet</servlet-class>
By default "ContextLoaderPlugIn" takes the spring configuration file name as <servlet-name>-servlet.xml,If the spring configuration file name is different then we need configure it using "contextConfigLocation" property.
2. Any request forward to D.A.P and the actual action class entry should be given in the spring configuration file, So that we can inject Service -> Action..
I) student.jsp M - I
<html:form action="StudentAction">
II struts-config.xmlM - I
<action path="/StudentAction"
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
1
1
123456789
101112131415161718192021222324252627282930313233343536373839404142434445464748495051
2 22-Jun spring- By Mr. Varma
type="org.springframework.web.struts.DelegatingActionProxy"/>
III) action-servlet.xmlM - I
<bean name="/StudentAction" class="edu.actions.StudentAction"/>
--DelegatingRequestProcessor2nd Approach : DelegatingRequestProcessor
Steps To integrate 1. Configure "ContextLoaderPlugIn" in the struts-config.xml to read the spring configuration file...
<plug-inclassName="org.springframework.web.struts.ContextLoaderPlugIn"><set-property property="contextConfigLocation"
value="/WEB-INF/ActionServlet-servlet.xml" /></plug-in>
Note : In the web.xml
<servlet-name>ActionServlet</servlet-name><servlet-class>
org.apache.struts.action.ActionServlet</servlet-class>
By default "ContextLoaderPlugIn" takes the spring configuration file name as <servlet-name>-servlet.xml,If the spring configuration file name is different then we need configure it using "contextConfigLocation" property.
2. In previous D.A.P example we are forwarding Any request to D.A.P and here don't configure any Action class name in the struts-config.xml (Don't give the type Attribute), Instead of configure it, Let's configure DelegatingRequestProcessor class in the struts-config.xml using <controller> tag..
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
Action class entry should be given in the spring configuration file, So that we can inject Service -> Action..
I) student.jsp M - I
<html:form action="StudentAction">
II struts-config.xml
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
2
2
525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
3 22-Jun spring- By Mr. Varma
M - I<action path="/StudentAction"/>
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
III) action-servlet.xmlM - I
<bean name="/StudentAction" class="edu.actions.StudentAction"/>
--ActionSupportAnd4WithOutCLP3rd Approach : ActionSupport
Steps To integrate 1. Configure "ContextLoaderPlugIn" in the struts-config.xml to read the spring configuration file...
<plug-inclassName="org.springframework.web.struts.ContextLoaderPlugIn"><set-property property="contextConfigLocation"
value="/WEB-INF/ActionServlet-servlet.xml" /></plug-in>
Note : In the web.xml
<servlet-name>ActionServlet</servlet-name><servlet-class>
org.apache.struts.action.ActionServlet</servlet-class>
By default "ContextLoaderPlugIn" takes the spring configuration file name as <servlet-name>-servlet.xml,If the spring configuration file name is different then we need configure it using "contextConfigLocation" property.
2. In previous D.A.P and D.R.P example's we are giving Action class entry in the spring configuration file and here let's configure it in the struts configuration file and all the Action class should extend ActionSupport..
public class StudentAction extends ActionSupport {
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
ApplicationContext context = getWebApplicationContext();
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
3
3
103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
4 22-Jun spring- By Mr. Varma
Service service = (Service) context.getBean("service");}
}Note : Here we can the W.A.Context object from base class (ActionSupport), So that we can get the service object from the W.A.Context..
Action class entry is there in the struts configuration file, So that we can't inject Service -> Action..
I) student.jsp M - I
<html:form action="StudentAction">
II struts-config.xmlM - I
<action path="/StudentAction"type="edu.actions.StudentAction"/>
4th Approach : WithOutCLP**Note : Here We are not using Spring Web features to integratestruts & spring, We are using Spring core to read the spring configuration filein the ServiceFactory.
ServiceFactory : To read the spring Configuration file and when ever required return service object..In the Action class take help from S.Factory and get the service objects..
*****Note : D.A.P and D.R.P examples we are able to inject Service -> Action.ActionSupport and WithOutCLP examples we are not able to inject Service -> Action.===================================================
--StrutsSpringHibernate
Final Example : StrutsSpringHibernate
Steps :
1. Create a Web Project.2. Add Struts Capabilities and using struts-config.xml design create Action, Form and JSP.3. Add Spring Capabilites. [Select Core, Web, ORM].4. Add Hibernate Capabilites..Using Reverse Engineering Create POJO and HBM..Create Dao, Service ..etc and update Spring-configuration file With T.M.
Note : StudentForm Shouldn't be passed to dao becaz S.Form is Struts Specific So we are using
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
4
4
153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
5 22-Jun spring- By Mr. Varma
BeanUtils.copyProperties to copy StudentForm data
to Student... and pass student object to Dao....----------------------Most of projects we integrate struts and Spring using
DelegatingActionProxy and we don't use Processor becaz
if we want implement custom processor then it becomes complex... and we don't use ActionSupport also becaz we are not able to inject Service -> Action..
Ref : StrutsSpringHibernate Example
--ContextLoaderPlugIn
package org.springframework.web.struts;
import org.apache.struts.action.PlugIn;
public class ContextLoaderPlugIn implements PlugIn {public static final String DEFAULT_NAMESPACE_SUFFIX = "-servlet";public final void init(ActionServlet actionServlet, ModuleConfig
moduleConfig) throws ServletException {try {
this.webApplicationContext = initWebApplicationContext();onInit();
}catch (RuntimeException ex) {}
}protected WebApplicationContext initWebApplicationContext() throws
BeansException, IllegalStateException {WebApplicationContext parent =
WebApplicationContextUtils.getWebApplicationContext(getServletContext());
WebApplicationContext wac = createWebApplicationContext(parent);
// Publish the context as a servlet context attribute.String attrName = getServletContextAttributeName();getServletContext().setAttribute(attrName, wac);return wac;
}protected WebApplicationContext
createWebApplicationContext(WebApplicationContext parent)throws BeansException {
ConfigurableWebApplicationContext wac =(ConfigurableWebApplicationContext)
BeanUtils.instantiateClass(getContextClass());wac.setParent(parent);
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
5
5
203
205206207
209
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
6 22-Jun spring- By Mr. Varma
wac.setServletContext(getServletContext());wac.setNamespace(getNamespace());if (getContextConfigLocation() != null) {
wac.setConfigLocations( StringUtils.tokenizeToStringArray(
getContextConfigLocation(), ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
}wac.refresh();return wac;
}public String getNamespace() {
if (this.namespace != null) {return this.namespace;
}if (this.actionServlet != null) {
return this.actionServlet.getServletName() + DEFAULT_NAMESPACE_SUFFIX;
}return null;
}}
The actual Flow :
ActionServlet.init() -> ActionServlet.initModulePlugIns() [plugIn.init()] ->ContextLoaderPlugIn.init() ->ContextLoaderPlugIn.initWebApplicationContext() -> ContextLoaderPlugIn.createWebApplicationContext() ->ContextLoaderPlugIn.getNamespace() <=|
Note : "ContextLoaderPlugIn" is used to read the spring-configuration file and create WebApplicationContext object and keep the W.A.Context object in Servlet Context Scope..
--DelegatingActionProxy
package org.springframework.web.struts;
import org.apache.struts.action.Action;
public class DelegatingActionProxy extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
Action delegateAction = getDelegateAction(mapping);
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
6
6
253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
7 22-Jun spring- By Mr. Varma
return delegateAction.execute(mapping, form, request, response);
}protected Action getDelegateAction(ActionMapping mapping) throws
BeansException {WebApplicationContext wac =
getWebApplicationContext(getServlet(), mapping.getModuleConfig());String beanName = determineActionBeanName(mapping);return (Action) wac.getBean(beanName, Action.class);
}protected WebApplicationContext getWebApplicationContext(
ActionServlet actionServlet, ModuleConfig moduleConfig) throws IllegalStateException {
return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet, moduleConfig);
}protected String determineActionBeanName(ActionMapping mapping) {
return DelegatingActionUtils.determineActionBeanName(mapping);}
}
public abstract class DelegatingActionUtils {public static WebApplicationContext
findRequiredWebApplicationContext(ActionServlet actionServlet, ModuleConfig moduleConfig)
throws IllegalStateException {
WebApplicationContext wac = getWebApplicationContext(actionServlet, moduleConfig);
}public static WebApplicationContext getWebApplicationContext(
ActionServlet actionServlet, ModuleConfig moduleConfig) {return (WebApplicationContext)
actionServlet.getServletContext().getAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX +
modulePrefix);
}public static String determineActionBeanName(ActionMapping mapping)
{return mapping.getPath();
}}
Note : D.A.Proxy is delegating the request to the actual Action class.1. Get the W.A.C from S.Context.2. Identify the beanName. (It will resolve path, Here path and beanName both are same).
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
7
7
304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
8 22-Jun spring- By Mr. Varma
3. pass the beanName to W.A.Context and get the Action class object and call the execute method.--5.3DelegatingRequestProcessor.txtpackage org.springframework.web.struts;
import org.apache.struts.action.RequestProcessor;
public class DelegatingRequestProcessor extends RequestProcessor {
private WebApplicationContext webApplicationContext;
public void init(ActionServlet actionServlet, ModuleConfig moduleConfig) throws ServletException {
super.init(actionServlet, moduleConfig);if (actionServlet != null) {
this.webApplicationContext = initWebApplicationContext(actionServlet, moduleConfig);
}}
protected WebApplicationContext initWebApplicationContext(ActionServlet actionServlet, ModuleConfig moduleConfig)
throws IllegalStateException {
return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet, moduleConfig);
}
protected Action processActionCreate(HttpServletRequest request, HttpServletResponse response,
ActionMapping mapping)throws IOException {
Action action = getDelegateAction(mapping);if (action != null) {
return action;}return super.processActionCreate(request, response, mapping);
}
protected Action getDelegateAction(ActionMapping mapping) throws BeansException {
String beanName = determineActionBeanName(mapping);if (!getWebApplicationContext().containsBean(beanName)) {
return null;}return (Action) getWebApplicationContext().getBean(beanName,
Action.class);}
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
8
8
354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
9 22-Jun spring- By Mr. Varma
protected String determineActionBeanName(ActionMapping mapping) {return DelegatingActionUtils.determineActionBeanName(mapping);
}}
public abstract class DelegatingActionUtils {public static WebApplicationContext
findRequiredWebApplicationContext(ActionServlet actionServlet, ModuleConfig moduleConfig)
throws IllegalStateException {
WebApplicationContext wac = getWebApplicationContext(actionServlet, moduleConfig);
}public static WebApplicationContext getWebApplicationContext(
ActionServlet actionServlet, ModuleConfig moduleConfig) {return (WebApplicationContext)
actionServlet.getServletContext().getAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX +
modulePrefix);
}public static String determineActionBeanName(ActionMapping mapping)
{return mapping.getPath();
}}
Note : D.R.Processor is delegating the request to the actual Action class.1. Get the W.A.C from S.Context.2. Identify the beanName. (It will resolve path, Here path and beanName both are same).3. pass the beanName to W.A.Context and get and return the Action class object.** D.R.Processor is overriding processActionCreate and
it's using Spring W.A.C and resolving Action class object,If it is not able resolve from spring configuration then it willresolve from Struts configuration file becaz it's callingsuper.processActionCreate() Method..Here Action class object creation is done by spring and
the other flow is done by struts means population of the data,validation, calling Action.execute() and forwarding to the success/ failure page.
--ActionSupport
package org.springframework.web.struts;
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
9
9
405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
442443444445446
448449450451452453454
10 22-Jun spring- By Mr. Varma
import org.apache.struts.action.Action;
public abstract class ActionSupport extends Action {
private WebApplicationContext webApplicationContext;
public void setServlet(ActionServlet actionServlet) {super.setServlet(actionServlet);if (actionServlet != null) {
this.webApplicationContext = initWebApplicationContext(actionServlet);
onInit();}else {
onDestroy();}
}protected WebApplicationContext
initWebApplicationContext(ActionServlet actionServlet)throws IllegalStateException {
return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet, null);
}protected final WebApplicationContext getWebApplicationContext() {
return this.webApplicationContext;}
}
public abstract class DelegatingActionUtils {public static WebApplicationContext
findRequiredWebApplicationContext(ActionServlet actionServlet, ModuleConfig moduleConfig)
throws IllegalStateException {
WebApplicationContext wac = getWebApplicationContext(actionServlet, moduleConfig);
}public static WebApplicationContext getWebApplicationContext(
ActionServlet actionServlet, ModuleConfig moduleConfig) {return (WebApplicationContext)
actionServlet.getServletContext().getAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX +
modulePrefix);
}}
public class RequestProcessor {
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
10
10
455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
11 22-Jun spring- By Mr. Varma
protected HashMap actions = new HashMap(); protected Action processActionCreate(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws IOException {
String className = mapping.getType(); Action instance = null; synchronized (actions) {
// Return any existing Action instance of this class instance = (Action) actions.get(className); if (instance != null) { return (instance); } try { instance = (Action) RequestUtils.applicationInstance(className); } catch (Exception e) { } instance.setServlet(this.servlet); actions.put(className, instance); }
return (instance);
}}Note : REquestProcessor will call instance.setServlet() after creating action class object and this setServlet method
is getting WAC object from S.Context and keepping it in Action class..Using getWebApplicationContext() we are getting W.A.Context in the S.Action class..
--DelegatingActionProxy
--StudentAction.javapackage edu.actions;public class StudentAction extends Action {
private final static String SUCCESS = "success";private Service service;public void setService(Service service) {
this.service = service;}public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
StudentForm studentForm = (StudentForm) form;
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
11
11
506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
538539540541542543544545546547548549550551552553554555
12 22-Jun spring- By Mr. Varma
System.out.println(".StudentAction.execute(..).START");service.serviceMethod();System.out.println(".StudentAction.execute(..).END");return mapping.findForward(StudentAction.SUCCESS);
}}
--Dao.javapackage edu.dao;public interface Dao {
public void daoMethod();}
--DaoImpl.javapackage edu.dao;public class DaoImpl implements Dao {
public void daoMethod() {System.out.println(".DaoImpl.daoMethod().START");System.out.println(".Persistance Logic.");System.out.println(".DaoImpl.daoMethod().END");
}}
--StudentForm.javapackage edu.forms;public class StudentForm extends ActionForm {
private String studentNo;private String studentName;public String getStudentNo() {
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}
}
--Service.javapackage edu.service;public interface Service {
public void serviceMethod();}
--ServiceImpl.javapackage edu.service;public class ServiceImpl implements Service {
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
12
12
556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
13 22-Jun spring- By Mr. Varma
private Dao dao;public void setDao(Dao dao) {
this.dao = dao;}public void serviceMethod() {
System.out.println(".ServiceImpl.serviceMethod().START");dao.daoMethod();System.out.println(".ServiceImpl.serviceMethod().END");
}}
--action-servlet.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dao" class="edu.dao.DaoImpl"></bean><bean id="service" class="edu.service.ServiceImpl">
<property name="dao"><ref bean="dao" />
</property></bean><bean name="/StudentAction" class="edu.actions.StudentAction">
<property name="service"><ref bean="service" />
</property></bean>
</beans>
--struts-config.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<form-beans><form-bean name="StudentForm" type="edu.forms.StudentForm" />
</form-beans><action-mappings>
<action name="StudentForm" path="/StudentAction"
type="org.springframework.web.struts.DelegatingActionProxy" scope="request">
<forward name="success" path="/WEB-INF/student/success.jsp" />
</action></action-mappings><plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
13
13
607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
649650652653654655656657
14 22-Jun spring- By Mr. Varma
<set-property property="contextConfigLocation"value="/WEB-INF/action-servlet.xml" />
</plug-in></struts-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>student.jsp</welcome-file> </welcome-file-list></web-app>
--student.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><html:form action="StudentAction">
<center><table border="1">
<tr><th>
Student No :</th><td>
<html:text property="studentNo" /></td>
</tr><tr>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
14
14
658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
15 22-Jun spring- By Mr. Varma
<th>Student Name :
</th><td>
<html:text property="studentName" /></td>
</tr><tr>
<td colspan="2" align="center"><html:submit value="submit" />
</td></tr>
</table><br>
</center></html:form>
</body></html:html>
--success.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><center>
<table border="1"><tr>
<th>Student No :
</th><td>
<bean:write name="StudentForm" property="studentNo" />
</td></tr><tr>
<th>Student Name :
</th><td>
<bean:write name="StudentForm" property="studentName" />
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
15
15
709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
16 22-Jun spring- By Mr. Varma
</td></tr>
</table><br>
</center></body></html:html>
--DelegatingRequestProcessor
--StudentAction.javapackage edu.actions;public class StudentAction extends Action {
private final static String SUCCESS = "success";private Service service;public void setService(Service service) {
this.service = service;}public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
StudentForm studentForm = (StudentForm) form;System.out.println(".StudentAction.execute(..).START");service.serviceMethod();System.out.println(".StudentAction.execute(..).END");return mapping.findForward(StudentAction.SUCCESS);
}}
--Dao.javapackage edu.dao;public interface Dao {
public void daoMethod();}
--DaoImpl.javapackage edu.dao;public class DaoImpl implements Dao {
public void daoMethod() {System.out.println(".DaoImpl.daoMethod().START");System.out.println(".Persistance Logic.");System.out.println(".DaoImpl.daoMethod().END");
}}
--StudentForm.javapackage edu.forms;public class StudentForm extends ActionForm {
private String studentNo;private String studentName;public String getStudentNo() {
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
16
16
760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
17 22-Jun spring- By Mr. Varma
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}
}
--Service.javapackage edu.service;public interface Service {
public void serviceMethod();}
--ServiceImpl.javapackage edu.service;public class ServiceImpl implements Service {
private Dao dao;public void setDao(Dao dao) {
this.dao = dao;}public void serviceMethod() {
System.out.println(".ServiceImpl.serviceMethod().START");dao.daoMethod();System.out.println(".ServiceImpl.serviceMethod().END");
}}
--action-servlet.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dao" class="edu.dao.DaoImpl"></bean><bean id="service" class="edu.service.ServiceImpl">
<property name="dao"><ref bean="dao" />
</property></bean><bean name="/StudentAction" class="edu.actions.StudentAction">
<property name="service"><ref bean="service" />
</property></bean>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
17
17
811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
18 22-Jun spring- By Mr. Varma
</beans>
--struts-config.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<form-beans><form-bean name="StudentForm" type="edu.forms.StudentForm" />
</form-beans><action-mappings>
<action name="StudentForm" path="/StudentAction" scope="request">
<forward name="success" path="/WEB-INF/student/success.jsp" />
</action></action-mappings><controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/action-servlet.xml" />
</plug-in></struts-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>student.jsp</welcome-file> </welcome-file-list></web-app>
--student.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
18
18
862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
19 22-Jun spring- By Mr. Varma
<html:html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><html:form action="StudentAction">
<center><table border="1">
<tr><th>
Student No :</th><td>
<html:text property="studentNo" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<html:text property="studentName" /></td>
</tr><tr>
<td colspan="2" align="center"><html:submit value="submit" />
</td></tr>
</table><br>
</center></html:form>
</body></html:html>
--success.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
19
19
913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
20 22-Jun spring- By Mr. Varma
<center><h1>
Student Details</h1>
</center><center>
<table border="1"><tr>
<th>Student No :
</th><td>
<bean:write name="StudentForm" property="studentNo" />
</td></tr><tr>
<th>Student Name :
</th><td>
<bean:write name="StudentForm" property="studentName" />
</td></tr>
</table><br>
</center></body></html:html>
--ActionSupport
--StudentAction.javapackage edu.actions;public class StudentAction extends ActionSupport {
private final static String SUCCESS = "success";public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
StudentForm studentForm = (StudentForm) form;ApplicationContext context = getWebApplicationContext();Service service = (Service) context.getBean("service");System.out.println(".StudentAction.execute(..).START");service.serviceMethod();System.out.println(".StudentAction.execute(..).END");return mapping.findForward(StudentAction.SUCCESS);
}}
--Dao.java
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
20
20
964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
21 22-Jun spring- By Mr. Varma
package edu.dao;public interface Dao {
public void daoMethod();}
--DaoImpl.javapackage edu.dao;public class DaoImpl implements Dao {
public void daoMethod() {System.out.println(".DaoImpl.daoMethod().START");System.out.println(".Persistance Logic.");System.out.println(".DaoImpl.daoMethod().END");
}}
--StudentForm.javapackage edu.forms;public class StudentForm extends ActionForm {
private String studentNo;private String studentName;public String getStudentNo() {
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}
}
--Service.javapackage edu.service;public interface Service {
public void serviceMethod();}
--ServiceImpl.javapackage edu.service;public class ServiceImpl implements Service {
private Dao dao;public void setDao(Dao dao) {
this.dao = dao;}public void serviceMethod() {
System.out.println(".ServiceImpl.serviceMethod().START");dao.daoMethod();System.out.println(".ServiceImpl.serviceMethod().END");
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
21
21
101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
22 22-Jun spring- By Mr. Varma
}}
--action-servlet.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dao" class="edu.dao.DaoImpl"></bean><bean id="service" class="edu.service.ServiceImpl">
<property name="dao"><ref bean="dao" />
</property></bean>
</beans>
--struts-config.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<form-beans><form-bean name="StudentForm" type="edu.forms.StudentForm" />
</form-beans><action-mappings>
<action name="StudentForm" path="/StudentAction" type="edu.actions.StudentAction"
scope="request"><forward name="success"
path="/WEB-INF/student/success.jsp" /></action>
</action-mappings><plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn"><set-property property="contextConfigLocation" value="/WEB-
INF/action-servlet.xml" /></plug-in>
</struts-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
22
22
106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
23 22-Jun spring- By Mr. Varma
<load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>student.jsp</welcome-file> </welcome-file-list></web-app>
--student.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><html:form action="StudentAction">
<center><table border="1">
<tr><th>
Student No :</th><td>
<html:text property="studentNo" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<html:text property="studentName" /></td>
</tr><tr>
<td colspan="2" align="center"><html:submit value="submit" />
</td></tr>
</table><br>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
23
23
111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
24 22-Jun spring- By Mr. Varma
</center></html:form>
</body></html:html>--success.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><center>
<table border="1"><tr>
<th>Student No :
</th><td>
<bean:write name="StudentForm" property="studentNo" />
</td></tr><tr>
<th>Student Name :
</th><td>
<bean:write name="StudentForm" property="studentName" />
</td></tr>
</table><br>
</center></body></html:html>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
24
24
116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
25 22-Jun spring- By Mr. Varma
--WithOutCLP
--StudentAction.javapackage edu.actions;public class StudentAction extends Action {
private final static String SUCCESS = "success";public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
StudentForm studentForm = (StudentForm) form;Service service = ServiceFactory.getService();System.out.println(".StudentAction.execute(..).START");service.serviceMethod();System.out.println(".StudentAction.execute(..).END");return mapping.findForward(StudentAction.SUCCESS);
}}
--Dao.javapackage edu.dao;public interface Dao {
public void daoMethod();}
--DaoImpl.javapackage edu.dao;public class DaoImpl implements Dao {
public void daoMethod() {System.out.println(".DaoImpl.daoMethod().START");System.out.println(".Persistance Logic.");System.out.println(".DaoImpl.daoMethod().END");
}}
--ServiceFactory.javapackage edu.factory;public class ServiceFactory {
private static ApplicationContext context = new ClassPathXmlApplicationContext(
"spring-config.xml");private static String SERVICE = "service";public static Service getService() {
return (Service) context.getBean(ServiceFactory.SERVICE);}
}
--StudentForm.javapackage edu.forms;public class StudentForm extends ActionForm {
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
25
25
121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
26 22-Jun spring- By Mr. Varma
private String studentNo;private String studentName;public String getStudentNo() {
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}
}
--Service.javapackage edu.service;public interface Service {
public void serviceMethod();}
--ServiceImpl.javapackage edu.service;public class ServiceImpl implements Service {
private Dao dao;public void setDao(Dao dao) {
this.dao = dao;}public void serviceMethod() {
System.out.println(".ServiceImpl.serviceMethod().START");dao.daoMethod();System.out.println(".ServiceImpl.serviceMethod().END");
}}
--spring-config.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dao" class="edu.dao.DaoImpl"></bean><bean id="service" class="edu.service.ServiceImpl">
<property name="dao"><ref bean="dao" />
</property></bean>
</beans>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
26
26
127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
27 22-Jun spring- By Mr. Varma
--struts-config.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<form-beans><form-bean name="StudentForm" type="edu.forms.StudentForm" />
</form-beans><action-mappings>
<action name="StudentForm" path="/StudentAction" type="edu.actions.StudentAction"
scope="request"><forward name="success"
path="/WEB-INF/student/success.jsp" /></action>
</action-mappings></struts-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>student.jsp</welcome-file> </welcome-file-list></web-app>
--student.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
27
27
132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
28 22-Jun spring- By Mr. Varma
</h1></center><html:form action="StudentAction">
<center><table border="1">
<tr><th>
Student No :</th><td>
<html:text property="studentNo" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<html:text property="studentName" /></td>
</tr><tr>
<td colspan="2" align="center"><html:submit value="submit" />
</td></tr>
</table><br>
</center></html:form>
</body></html:html>
--success.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><center>
<table border="1"><tr>
<th>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
28
28
137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
29 22-Jun spring- By Mr. Varma
Student No :</th><td>
<bean:write name="StudentForm" property="studentNo" />
</td></tr><tr>
<th>Student Name :
</th><td>
<bean:write name="StudentForm" property="studentName" /></td>
</tr></table><br>
</center></body></html:html>
--StrutsSpringHibernate
--StudentAction.javapackage edu.actions;public class StudentAction extends Action {
private final static String SUCCESS = "success";private StudentService studentService;public void setStudentService(StudentService studentService) {
this.studentService = studentService;}public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
29
29
1423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
144514461447144814491450145114521453145414551456
30 22-Jun spring- By Mr. Varma
StudentForm studentForm = (StudentForm) form;Student student = new Student();// student.setStudentNo(studentForm.getStudentNo());BeanUtils.copyProperties(student, studentForm);System.out.println(".StudentAction.execute(..).START");studentService.insertStudent(student);System.out.println(".StudentAction.execute(..).END");return mapping.findForward(StudentAction.SUCCESS);
}}
--StudentDao.javapackage edu.dao;public interface StudentDao {
public void insertStudent(Student student);}
--StudentDaoImpl.javapackage edu.dao;public class StudentDaoImpl extends HibernateDaoSupport implements StudentDao {
public void insertStudent(Student student) {getSession().save(student);
}}
--StudentForm.javapackage edu.forms;public class StudentForm extends ActionForm {
private String studentNo;private String studentName;public String getStudentNo() {
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}
}
--Student.javapackage edu.model;public class Student {
private String studentNo;private String studentName;public String getStudentNo() {
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
30
30
145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
31 22-Jun spring- By Mr. Varma
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}
}
--StudentService.javapackage edu.service;public interface StudentService {
public void insertStudent(Student student) ;}
--StudentServiceImpl.javapackage edu.service;public class StudentServiceImpl implements StudentService {
private StudentDao studentDao;public void setStudentDao(StudentDao studentDao) {
this.studentDao = studentDao;}public void insertStudent(Student student) {
studentDao.insertStudent(student);}
}
--.properties# Resources for parameter ''# Project StrutsSpringHibernate
--student.hbm.xml<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping>
<class name="edu.model.Student" table="STUDENT"><id name="studentNo" column="SNO">
<generator class="assigned" /></id><property name="studentName" column="SNAME" type="string" />
</class></hibernate-mapping>
--action-servlet.xml<?xml version="1.0" encoding="UTF-8"?>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
31
31
150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
32 22-Jun spring- By Mr. Varma
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!-- 1.1. Create the DS Object --><bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"><property name="jndiName">
<value>jdbc/studentJNDI</value></property>
</bean><!-- 1.2. Create the SessionFactory Object --><bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource">
<ref bean="dataSource" /></property><property name="hibernateProperties">
<props><prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect</prop><prop key="hibernate.show_sql">true</prop>
</props></property><property name="mappingResources">
<list><value>edu/mapping/student.hbm.xml</value>
</list></property>
</bean><!-- 2.1. Create the TransactionManager Object --><bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory">
<ref bean="sessionFactory" /></property>
</bean><!-- 1.3. Create the Dao Object --><bean id="studentDao" class="edu.dao.StudentDaoImpl">
<property name="sessionFactory"><ref bean="sessionFactory" />
</property></bean><!-- 1.4. Create the Service Object --><bean id="studentServiceTarget"
class="edu.service.StudentServiceImpl"><property name="studentDao">
<ref bean="studentDao" />
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
32
32
15591560156115621563156415651566156715681569157015711572
157315751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
33 22-Jun spring- By Mr. Varma
</property></bean><!--
Apply Transactions on Servce Layer....Using Declarative Transactions..
--><bean id="studentService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager" />
</property><property name="target">
<ref bean="studentServiceTarget" /></property><property name="transactionAttributes">
<props><prop key="*">
PROPAGATION_REQUIRED,-StudentException</prop>
</props></property>
</bean><bean name="/StudentAction" class="edu.actions.StudentAction">
<property name="studentService"><ref bean="studentService" />
</property></bean>
</beans>--struts-config.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<form-beans><form-bean name="StudentForm" type="edu.forms.StudentForm" />
</form-beans><action-mappings>
<action name="StudentForm" path="/StudentAction"
type="org.springframework.web.struts.DelegatingActionProxy" scope="request">
<forward name="success" path="/WEB-INF/student/success.jsp" />
</action></action-mappings><plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
33
33
1610161116121613161416151616
1617161816191621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651
16521653165516561657165816591660
34 22-Jun spring- By Mr. Varma
<set-property property="contextConfigLocation" value="/WEB-INF/action-servlet.xml" />
</plug-in></struts-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>student.jsp</welcome-file> </welcome-file-list></web-app>
--student.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><html:form action="StudentAction">
<center><table border="1">
<tr><th>
Student No :</th><td>
<html:text property="studentNo" /></td>
</tr><tr>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
34
34
166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
35 22-Jun spring- By Mr. Varma
<th>Student Name :
</th><td>
<html:text property="studentName" /></td>
</tr><tr>
<td colspan="2" align="center"><html:submit value="submit" />
</td></tr>
</table><br>
</center></html:form>
</body></html:html>
--success.jsp<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%><%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><center>
<table border="1"><tr>
<th>Student No :
</th><td>
<bean:write name="StudentForm" property="studentNo" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<bean:write name="StudentForm" property="studentName" /></td>
</tr>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
35
35
171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762
36 22-Jun spring- By Mr. Varma
</table><br>
</center></body></html:html>
--BaseDelegatingActionProxy
--StudentAction.java/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package edu.action;public class StudentAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
{StudentForm StudentForm = (StudentForm) form;// TODO Auto-
generated// method stubreturn mapping.findForward("success");
}}
--StudentForm.java/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package edu.form;/** * MyEclipse Struts * Creation date: 05-07-2011 * * XDoclet definition: * @struts.form name="StudentForm" */public class StudentForm extends ActionForm {
/* * Generated fields *//** studentNo property */private String studentNo;/** studentName property */private String studentName;/* * Generated Methods *//** * Returns the studentNo. * @return String
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
36
36
176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
37 22-Jun spring- By Mr. Varma
*/public String getStudentNo() {
return studentNo;}/** * Set the studentNo. * @param studentNo The studentNo to set */public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}/** * Returns the studentName. * @return String */public String getStudentName() {
return studentName;}/** * Set the studentName. * @param studentName The studentName to set */public void setStudentName(String studentName) {
this.studentName = studentName;}
}
--BaseContextLoaderPlugIn.javapackage org.spring;public class BaseContextLoaderPlugIn implements PlugIn {
private String contextConfigLocation;public void setContextConfigLocation(String contextConfigLocation) {
this.contextConfigLocation = contextConfigLocation;}public void init(ActionServlet actionServlet, ModuleConfig
moduleConfig)throws ServletException {
if (contextConfigLocation == null) {contextConfigLocation = actionServlet.getServletName()
+ "-servlet.xml";}ApplicationContext context = new
ClassPathXmlApplicationContext(contextConfigLocation);
actionServlet.getServletContext().setAttribute("appContext", context);
}public void destroy() {
System.out.println("BaseContextLoaderPlugIn.destroy()");}
}
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
37
37
181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
38 22-Jun spring- By Mr. Varma
--BaseDelegatingActionProxy.javapackage org.spring;public class BaseDelegatingActionProxy extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
String beanName = mapping.getPath();ApplicationContext context = (ApplicationContext) servlet
.getServletContext().getAttribute("appContext");Action action = (Action) context.getBean(beanName);return action.execute(mapping, form, request, response);
}}
--.properties# Resources for parameter ''# Project BaseDelegatingActionProxy
--action-servlet.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean name="/StudentAction" class="edu.action.StudentAction" /></beans>
--struts-config.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<form-beans><form-bean name="StudentForm" type="edu.form.StudentForm" />
</form-beans><action-mappings>
<action attribute="StudentForm" input="student.jsp" name="StudentForm"
path="/StudentAction" scope="request" type="org.spring.BaseDelegatingActionProxy">
<forward name="success" path="/success.jsp" /></action>
</action-mappings><plug-in className="org.spring.BaseContextLoaderPlugIn">
<!-- <set-property property="contextConfigLocation" value="action-servlet.xml" /> -->
</plug-in></struts-config>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
38
38
186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
39 22-Jun spring- By Mr. Varma
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><servlet>
<servlet-name>action</servlet-name><servlet-class>org.apache.struts.action.ActionServlet</servlet-
class><load-on-startup>0</load-on-startup>
</servlet><servlet-mapping>
<servlet-name>action</servlet-name><url-pattern>*.do</url-pattern>
</servlet-mapping><welcome-file-list>
<welcome-file>student.jsp</welcome-file></welcome-file-list>
</web-app>
--student.jsp<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><html:form action="StudentAction">
<center><table border="1">
<tr><th>
Student No :</th><td>
<html:text property="studentNo" /></td>
</tr><tr>
<th>Student Name :
</th>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
39
39
191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966
40 22-Jun spring- By Mr. Varma
<td><html:text property="studentName" />
</td></tr><tr>
<td colspan="2" align="center"><html:submit value="submit" />
</td></tr>
</table><br>
</center></html:form>
</body></html:html>
--success.jsp<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>SUCCESS
</h1></center>
</body></html:html>
--BaseDelegatingRequestProcessor
--StudentAction.java/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package edu.action;public class StudentAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
{StudentForm StudentForm = (StudentForm) form;// TODO Auto-
generated// method stubreturn mapping.findForward("success");
}}
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
40
40
196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
41 22-Jun spring- By Mr. Varma
--StudentForm.java/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package edu.form;/** * MyEclipse Struts * Creation date: 05-07-2011 * * XDoclet definition: * @struts.form name="StudentForm" */public class StudentForm extends ActionForm {
/* * Generated fields *//** studentNo property */private String studentNo;/** studentName property */private String studentName;/* * Generated Methods *//** * Returns the studentNo. * @return String */public String getStudentNo() {
return studentNo;}/** * Set the studentNo. * @param studentNo The studentNo to set */public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}/** * Returns the studentName. * @return String */public String getStudentName() {
return studentName;}/** * Set the studentName. * @param studentName The studentName to set */public void setStudentName(String studentName) {
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
41
41
201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068
42 22-Jun spring- By Mr. Varma
this.studentName = studentName;}
}
--BaseContextLoaderPlugIn.javapackage org.spring;public class BaseContextLoaderPlugIn implements PlugIn {
private String contextConfigLocation;public void setContextConfigLocation(String contextConfigLocation) {
this.contextConfigLocation = contextConfigLocation;}public void init(ActionServlet actionServlet, ModuleConfig
moduleConfig)throws ServletException {
if (contextConfigLocation == null) {contextConfigLocation = actionServlet.getServletName()
+ "-servlet.xml";}ApplicationContext context = new
ClassPathXmlApplicationContext(contextConfigLocation);
actionServlet.getServletContext().setAttribute("appContext", context);
}public void destroy() {
System.out.println("BaseContextLoaderPlugIn.destroy()");}
}
--BaseDelegatingRequestProcessor.javapackage org.spring;public class BaseDelegatingRequestProcessor extends RequestProcessor {
private ApplicationContext context;public void init(ActionServlet servlet, ModuleConfig moduleConfig)
throws ServletException {this.context = (ApplicationContext) servlet.getServletContext()
.getAttribute("appContext");super.init(servlet, moduleConfig);
}protected Action processActionCreate(HttpServletRequest request,
HttpServletResponse response, ActionMapping mapping)throws IOException {
String beanName = mapping.getPath();Action action = (Action) context.getBean(beanName);if (action != null) {
return action;}return super.processActionCreate(request, response, mapping);
}}
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
42
42
206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
43 22-Jun spring- By Mr. Varma
--.properties# Resources for parameter ''# Project BaseDelegatingActionProxy
--action-servlet.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean name="/StudentAction" class="edu.action.StudentAction" /></beans>
--struts-config.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<form-beans><form-bean name="StudentForm" type="edu.form.StudentForm" />
</form-beans><action-mappings>
<action attribute="StudentForm" input="student.jsp" name="StudentForm"
path="/StudentAction" scope="request"><forward name="success" path="/success.jsp" />
</action></action-mappings><controller
processorClass="org.spring.BaseDelegatingRequestProcessor" /><plug-in className="org.spring.BaseContextLoaderPlugIn">
<!--<set-property property="contextConfigLocation"value="action-servlet.xml" />
--></plug-in>
</struts-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><servlet>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
43
43
212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170
44 22-Jun spring- By Mr. Varma
<servlet-name>action</servlet-name><servlet-class>org.apache.struts.action.ActionServlet</servlet-
class><load-on-startup>0</load-on-startup>
</servlet><servlet-mapping>
<servlet-name>action</servlet-name><url-pattern>*.do</url-pattern>
</servlet-mapping><welcome-file-list>
<welcome-file>student.jsp</welcome-file></welcome-file-list>
</web-app>
--student.jsp<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><html:form action="StudentAction">
<center><table border="1">
<tr><th>
Student No :</th><td>
<html:text property="studentNo" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<html:text property="studentName" /></td>
</tr><tr>
<td colspan="2" align="center"><html:submit value="submit" />
</td></tr>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
44
44
217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221
45 22-Jun spring- By Mr. Varma
</table><br>
</center></html:form>
</body></html:html>
--success.jsp<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>SUCCESS
</h1></center>
</body></html:html>
--BaseActionSupport
--StudentAction.java/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package edu.action;public class StudentAction extends ActionSupport {
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
{StudentForm StudentForm = (StudentForm) form;// TODO Auto-
generatedSystem.out.println("WebApplicationContext :"
+ getWebApplicationContext());return mapping.findForward("success");
}}
--StudentForm.java/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package edu.form;/** * MyEclipse Struts
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
45
45
222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272
46 22-Jun spring- By Mr. Varma
* Creation date: 05-07-2011 * * XDoclet definition: * @struts.form name="StudentForm" */public class StudentForm extends ActionForm {
/* * Generated fields *//** studentNo property */private String studentNo;/** studentName property */private String studentName;/* * Generated Methods *//** * Returns the studentNo. * @return String */public String getStudentNo() {
return studentNo;}/** * Set the studentNo. * @param studentNo The studentNo to set */public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}/** * Returns the studentName. * @return String */public String getStudentName() {
return studentName;}/** * Set the studentName. * @param studentName The studentName to set */public void setStudentName(String studentName) {
this.studentName = studentName;}
}
--ActionSupport.javapackage org.spring;public class ActionSupport extends Action {
private ApplicationContext context;protected ApplicationContext getWebApplicationContext() {
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
46
46
227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323
47 22-Jun spring- By Mr. Varma
return context;}public void setServlet(ActionServlet servlet) {
this.context = (ApplicationContext) servlet.getServletContext().getAttribute("appContext");
super.setServlet(servlet);}
}
--BaseContextLoaderPlugIn.javapackage org.spring;public class BaseContextLoaderPlugIn implements PlugIn {
private String contextConfigLocation;public void setContextConfigLocation(String contextConfigLocation) {
this.contextConfigLocation = contextConfigLocation;}public void init(ActionServlet actionServlet, ModuleConfig
moduleConfig)throws ServletException {
if (contextConfigLocation == null) {contextConfigLocation = actionServlet.getServletName()
+ "-servlet.xml";}ApplicationContext context = new
ClassPathXmlApplicationContext(contextConfigLocation);
actionServlet.getServletContext().setAttribute("appContext", context);
}public void destroy() {
System.out.println("BaseContextLoaderPlugIn.destroy()");}
}
--.properties# Resources for parameter ''# Project BaseDelegatingActionProxy
--action-servlet.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean name="/StudentAction" class="edu.action.StudentAction" /></beans>
--struts-config.xml<?xml version="1.0" encoding="UTF-8"?>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
47
47
23242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373
48 22-Jun spring- By Mr. Varma
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
<form-beans><form-bean name="StudentForm" type="edu.form.StudentForm" />
</form-beans><action-mappings>
<action attribute="StudentForm" input="student.jsp" name="StudentForm"
path="/StudentAction" type="edu.action.StudentAction" scope="request">
<forward name="success" path="/success.jsp" /></action>
</action-mappings><plug-in className="org.spring.BaseContextLoaderPlugIn">
<!--<set-property property="contextConfigLocation"value="action-servlet.xml" />
--></plug-in>
</struts-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><servlet>
<servlet-name>action</servlet-name><servlet-class>org.apache.struts.action.ActionServlet</servlet-
class><load-on-startup>0</load-on-startup>
</servlet><servlet-mapping>
<servlet-name>action</servlet-name><url-pattern>*.do</url-pattern>
</servlet-mapping><welcome-file-list>
<welcome-file>student.jsp</welcome-file></welcome-file-list>
</web-app>
--student.jsp<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>student.jsp</title></head>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
48
48
237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424
49 22-Jun spring- By Mr. Varma
<body bgcolor="wheat"><br><center>
<h1>Student Details
</h1></center><html:form action="StudentAction">
<center><table border="1">
<tr><th>
Student No :</th><td>
<html:text property="studentNo" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<html:text property="studentName" /></td>
</tr><tr>
<td colspan="2" align="center"><html:submit value="submit" />
</td></tr>
</table><br>
</center></html:form>
</body></html:html>
--success.jsp<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%><html:html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>SUCCESS
</h1></center></body></html:html>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
49
49
242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475
50 22-Jun spring- By Mr. Varma
--BasicJSFSpring & JSF.......JSF Basic...
Struts JSF1. Action/ Form Java Bean2. struts-config.xml faces-config.xml3. Action Tags... managed-bean4. Forward Tags.. navigation-rule5. name attribute from-outcome6. path attribute to-view-id7. ActionServlet FacesServlet8. <html:text/> <h:inputText/>9. <html:submit/> <h:commandButton/>10. <bean:write/> <h:outputText/>----------Note : In struts directly we can call student.jsp and here Don't call the student.jsp.Forward the request to FacesServelt which will display student.jsp. The forward logic is there in the index.jsp and we are giving it in the web.xml
== index.jsp<jsp:forward page="student.faces" />
It will be forwaded to "FacesServlet" and it will display student.jsp
JSF is the specification and the implementation is doneby Icefaces/MyFaces/RichFaces....etc.
1. In JSF the same application UI we can use both Server Side and Mobile application...2. The complete UI, We can controll at server side.3. Like swing applications, We can do event handlingin the web application using JSF.
--DelegatingVariableResolver==> Spring & JSF
What configuration files are required?
1. web.xml : Servlets entries..2. faces-config.xml : JSF entries..3. spring-config.xml : Spring entries [applicationContext.xml]..
There is 1 way, provided by spring to integrate JSF & Spring..
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
50
50
247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526
51 22-Jun spring- By Mr. Varma
1. DelegatingVariableResolver/SpringBeanVariableResolver
1st Approach : DelegatingVariableResolver
Steps To integrate 1. Configure "ContextLoaderListener" in the web.xml file to read the spring configuration file...
<listener><listener-
class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
By default "ContextLoaderListener" takes the spring configuration file name as "applicationContext.xml",If the spring configuration file name is different then we need configure it using "contextConfigLocation" property.
2. To inject service -> Bean (Student), Let's configure "DelegatingVariableResolver" in the "faces-config.xml".
Note : 1. Here we are giving JSF Bean entry in the "faces-config.xml" file and service class entry in the "applicationContext.xml". 2. We need to inject Service -> Bean so let's configure it in the "faces-config.xml" using <managed-property>
<property-name>service</property-name><value>#{service}</value>
</managed-property>
<managed-property/> is similar to <propery/> in Spring.
"DelegatingVariableResolver" will resolve spring configuration file entries in the JSF configuration file...
--FacesContexttAndWithOutCLL2nd Approach : FacesContext
Steps To integrate 1. Configure "ContextLoaderListener" in the web.xml file to read the spring configuration file...
<listener><listener-
class>org.springframework.web.context.ContextLoaderListener</listener-class>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
51
51
252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577
52 22-Jun spring- By Mr. Varma
</listener>
By default "ContextLoaderListener" takes the spring configuration file name as "applicationContext.xml",If the spring configuration file name is different then we need configure it using "contextConfigLocation" property.
2. We are not injecting service -> Bean (Student), So"DelegatingVariableResolver" is not required in the "faces-config.xml".Here we are writing ServiceFactory and it's used To get the Service object in the Bean class.In the service Factory we required 2.1 S.C to get W.A.C. 2.2 "request" to get S.C. and "request" object is not available so to S.C We are using "FacesContext"..Final points.. Get the FacesContext, Get the S.C from F.Context, Get the W.A.C from S.C and Get the service object from W.A.C.
Note : We are not injecting service -> Beans, So Let's get the service object in the bean class using ServiceFactory....===================================================3rd Approach : WithOutCLLHere We are not using "ContextLoaderListener" to read the spring configuration file and We are not using "D.V.Resolver" also so we can't inject service -> Bean
**Note : Here We are not using Spring Web features to integrate JSF & spring, We are using Spring core to read the spring configuration file in the ServiceFactory.
ServiceFactory : To read the spring Configuration file and when ever we required return service object..In the Bean class take help from S.Factory and get the service objects..
***Note : 1. DelegatingVariableResolver example we are able to inject Service -> Bean.2. FacesContext and WithOutCLL examples we are not able to inject Service -> Bean.===================================================
--SpringJSFJPA==> 4SpringJSFJPA
Steps To integrate
1. Create the Web Project.2. Add the JSF capabilities.3. Add the Spring capabilities.
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
52
52
257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628
53 22-Jun spring- By Mr. Varma
4. Add the JPA capabilities.To integrate SpringJSFJPA follow "Spring & JSF" and "Spring & JPA" steps.. [DelegatingVariableResolver and 1LocalEntityManagerFactoryBean example Steps]
--ContextLoaderListenerpackage org.springframework.web.context;
import javax.servlet.ServletContextListener;
public class ContextLoaderListener implements ServletContextListener {public void contextInitialized(ServletContextEvent event) {
this.contextLoader = createContextLoader();
this.contextLoader.initWebApplicationContext(event.getServletContext());}protected ContextLoader createContextLoader() {
return new ContextLoader();}public void contextDestroyed(ServletContextEvent event) {
if (this.contextLoader != null) {
this.contextLoader.closeWebApplicationContext(event.getServletContext());}
}}
public class ContextLoader {private WebApplicationContext context;public WebApplicationContext
initWebApplicationContext(ServletContext servletContext)throws IllegalStateException, BeansException {
try {// Determine parent for root web application context, if
any.ApplicationContext parent =
loadParentContext(servletContext);
// Store context in local instance variable, to guarantee that
// it is available on ServletContext shutdown.this.context =
createWebApplicationContext(servletContext, parent);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
return this.context;}
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
53
53
2629263026312632263326342635263626372638263926402641
26422643264526462647264826492650
2651265226542655265626572658265926602661266226632664266526662667266826692670267126722673
26742675267626782679
54 22-Jun spring- By Mr. Varma
catch (RuntimeException ex) {}catch (Error err) {}
}protected WebApplicationContext createWebApplicationContext(
ServletContext servletContext, ApplicationContext parent) throws BeansException {
Class contextClass = determineContextClass(servletContext);
ConfigurableWebApplicationContext wac =(ConfigurableWebApplicationContext)
BeanUtils.instantiateClass(contextClass);wac.setParent(parent);wac.setServletContext(servletContext);String configLocation =
servletContext.getInitParameter(CONFIG_LOCATION_PARAM);if (configLocation != null) {
wac.setConfigLocations(StringUtils.tokenizeToStringArray(configLocation,
ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));}
wac.refresh();return wac;
}}
public interface WebApplicationContext extends ApplicationContext {String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE =
WebApplicationContext.class.getName() + ".ROOT";}
Note : "ContextLoaderListener" is taking help from "ContextLoader" and creating W.A.Context and keep the W.A.Context in S.Context scope..
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
54
54
2680268126822683268426852686268726882689269026912692269326942695269626972698
26992700
2702270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730
55 22-Jun spring- By Mr. Varma
--BasicJSF
--Student.javapackage edu.beans;//Student class is a simple Java Bean/ POJO ..etc//It contains both properties and execute() Method.public class Student {
private String studentNo;private String studentName;public String getStudentNo() {
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}// action() method is similar to execute()/ handleRequest()public String action() {
System.out.println("StudentBean.action()");return "success";
}}
--faces-config.xml<?xml version='1.0' encoding='UTF-8'?><faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"version="1.2"><managed-bean>
<managed-bean-name>Student</managed-bean-name><managed-bean-class>edu.beans.Student</managed-bean-class><managed-bean-scope>request</managed-bean-scope>
</managed-bean><navigation-rule>
<from-view-id>/student.jsp</from-view-id><navigation-case>
<from-outcome>success</from-outcome><to-view-id>/success.jsp</to-view-id>
</navigation-case>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
55
55
273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781
56 22-Jun spring- By Mr. Varma
</navigation-rule></faces-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>FacesServlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>FacesServlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
--index.jsp<jsp:forward page="student.faces" />
--student.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><h:form>
<center><table border="1">
<tr><th>
Student No :</th><td>
<h:inputText value="#{Student.studentNo}" /></td>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
56
56
278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832
57 22-Jun spring- By Mr. Varma
</tr><tr>
<th>Student Name :
</th><td>
<h:inputText value="#{Student.studentName}" /></td>
</tr><tr>
<td colspan="2" align="center"><h:commandButton action="#{Student.action}" value="SUBMIT" />
</td></tr>
</table><br>
</center></h:form>
</body></html>
</f:view>
--success.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><center>
<table border="1"><tr>
<th>Student No :
</th><td>
<h:outputText value="#{Student.studentNo}" />
</td></tr><tr>
<th>Student Name :
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
57
57
283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883
58 22-Jun spring- By Mr. Varma
</th><td>
<h:outputText value="#{Student.studentName}" /></td>
</tr></table><br>
</center></body>
</html></f:view>
--DelegatingVariableResolver
--Student.javapackage edu.beans;//Student class is a simple Java Bean/ POJO ..etc//It contains both properties and execute() Method.public class Student {
private String studentNo;private String studentName;private Service service;public String getStudentNo() {
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}public void setService(Service service) {
this.service = service;}// action() method is similar to execute()/ handleRequest()public String action() {
System.out.println(".StudentBean.action().START");service.serviceMethod(this);System.out.println(".StudentBean.action().END");return "success";
}}
--Dao.javapackage edu.dao;public interface Dao {
public void daoMethod(Student student);}
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
58
58
288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934
59 22-Jun spring- By Mr. Varma
--DaoImpl.javapackage edu.dao;public class DaoImpl implements Dao {
public void daoMethod(Student student) {System.out.println(".DaoImpl.daoMethod().START");System.out.println(".Persistance Logic.");System.out.println(".DaoImpl.daoMethod().END");
}}
--Service.javapackage edu.service;public interface Service {
public void serviceMethod(Student student);}
--ServiceImpl.javapackage edu.service;public class ServiceImpl implements Service {
private Dao dao;public void setDao(Dao dao) {
this.dao = dao;}public void serviceMethod(Student student) {
System.out.println(".ServiceImpl.serviceMethod().START");dao.daoMethod(student);System.out.println(".ServiceImpl.serviceMethod().END");
}}
--applicationContext.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dao" class="edu.dao.DaoImpl" /><bean id="service" class="edu.service.ServiceImpl">
<property name="dao"><ref bean="dao" />
</property></bean>
</beans>
--faces-config.xml<?xml version='1.0' encoding='UTF-8'?><faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
59
59
29352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984
60 22-Jun spring- By Mr. Varma
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2"><application>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
</application><managed-bean>
<managed-bean-name>Student</managed-bean-name><managed-bean-class>edu.beans.Student</managed-bean-class><managed-bean-scope>request</managed-bean-scope><managed-property>
<property-name>service</property-name><value>#{service}</value>
</managed-property></managed-bean><navigation-rule>
<from-view-id>/student.jsp</from-view-id><navigation-case>
<from-outcome>success</from-outcome><to-view-id>/success.jsp</to-view-id>
</navigation-case></navigation-rule>
</faces-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><context-param>
<param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param><listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener><servlet>
<servlet-name>FacesServlet</servlet-name><servlet-class>javax.faces.webapp.FacesServlet</servlet-class><load-on-startup>0</load-on-startup>
</servlet><servlet-mapping>
<servlet-name>FacesServlet</servlet-name><url-pattern>*.faces</url-pattern>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
60
60
29852986298729882989
299029912993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035
61 22-Jun spring- By Mr. Varma
</servlet-mapping><welcome-file-list>
<welcome-file>index.jsp</welcome-file></welcome-file-list>
</web-app>
--index.jsp<jsp:forward page="student.faces" />
--student.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><h:form>
<center><table border="1">
<tr><th>
Student No :</th><td>
<h:inputText value="#{Student.studentNo}" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<h:inputText value="#{Student.studentName}" /></td>
</tr><tr>
<td colspan="2" align="center"><h:commandButton action="#{Student.action}" value="SUBMIT" />
</td></tr>
</table><br>
</center>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
61
61
303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086
62 22-Jun spring- By Mr. Varma
</h:form></body>
</html></f:view>
--success.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><center>
<table border="1"><tr>
<th>Student No :
</th><td>
<h:outputText value="#{Student.studentNo}" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<h:outputText value="#{Student.studentName}" /></td>
</tr></table><br>
</center></body>
</html></f:view>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
62
62
308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137
63 22-Jun spring- By Mr. Varma
--FacesContext
--Student.javapackage edu.beans;//Student class is a simple Java Bean/ POJO ..etc//It contains both properties and execute() Method.public class Student {
private String studentNo;private String studentName;public String getStudentNo() {
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}// action() method is similar to execute()/ handleRequest()public String action() {
System.out.println(".StudentBean.action().START");Service service = (Service)
ServiceFactory.getService("service");service.serviceMethod(this);System.out.println(".StudentBean.action().END");return "success";
}}
--Dao.javapackage edu.dao;public interface Dao {
public void daoMethod(Student student);}
--DaoImpl.javapackage edu.dao;public class DaoImpl implements Dao {
public void daoMethod(Student student) {System.out.println(".DaoImpl.daoMethod().START");System.out.println(".Persistance Logic.");System.out.println(".DaoImpl.daoMethod().END");
}
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
63
63
313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188
64 22-Jun spring- By Mr. Varma
}
--ServiceFactory.javapackage edu.factory;public class ServiceFactory {
public static Object getService(String serviceName) {FacesContext context = FacesContext.getCurrentInstance();ServletContext servletContext = (ServletContext) context
.getExternalContext().getContext();ApplicationContext appContext = WebApplicationContextUtils
.getWebApplicationContext(servletContext);// appContext = (ApplicationContext) servletContext
// .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
return appContext.getBean(serviceName);}
}
--Service.javapackage edu.service;public interface Service {
public void serviceMethod(Student student);}
--ServiceImpl.javapackage edu.service;public class ServiceImpl implements Service {
private Dao dao;public void setDao(Dao dao) {
this.dao = dao;}public void serviceMethod(Student student) {
System.out.println(".ServiceImpl.serviceMethod().START");dao.daoMethod(student);System.out.println(".ServiceImpl.serviceMethod().END");
}}
--applicationContext.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dao" class="edu.dao.DaoImpl" /><bean id="service" class="edu.service.ServiceImpl">
<property name="dao"><ref bean="dao" />
</property>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
64
64
318931903191319231933194319531963197319831993200
32013202320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239
65 22-Jun spring- By Mr. Varma
</bean></beans>
--faces-config.xml<?xml version='1.0' encoding='UTF-8'?><faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"version="1.2"><managed-bean>
<managed-bean-name>Student</managed-bean-name><managed-bean-class>edu.beans.Student</managed-bean-class><managed-bean-scope>request</managed-bean-scope>
</managed-bean><navigation-rule>
<from-view-id>/student.jsp</from-view-id><navigation-case>
<from-outcome>success</from-outcome><to-view-id>/success.jsp</to-view-id>
</navigation-case></navigation-rule>
</faces-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><context-param>
<param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param><listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener><servlet>
<servlet-name>FacesServlet</servlet-name><servlet-class>javax.faces.webapp.FacesServlet</servlet-class><load-on-startup>0</load-on-startup>
</servlet><servlet-mapping>
<servlet-name>FacesServlet</servlet-name><url-pattern>*.faces</url-pattern>
</servlet-mapping><welcome-file-list>
<welcome-file>index.jsp</welcome-file>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
65
65
324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290
66 22-Jun spring- By Mr. Varma
</welcome-file-list></web-app>
--index.jsp<jsp:forward page="student.faces" />
--student.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><h:form>
<center><table border="1">
<tr><th>
Student No :</th><td>
<h:inputText value="#{Student.studentNo}" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<h:inputText value="#{Student.studentName}" /></td>
</tr><tr>
<td colspan="2" align="center"><h:commandButton action="#{Student.action}" value="SUBMIT" />
</td></tr>
</table><br>
</center></h:form>
</body></html>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
66
66
329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341
67 22-Jun spring- By Mr. Varma
</f:view>
--success.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><center>
<table border="1"><tr>
<th>Student No :
</th><td>
<h:outputText value="#{Student.studentNo}" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<h:outputText value="#{Student.studentName}" /></td>
</tr></table><br>
</center></body>
</html></f:view>
--WithOutCLL
--Student.javapackage edu.beans;//Student class is a simple Java Bean/ POJO ..etc//It contains both properties and execute() Method.public class Student {
private String studentNo;private String studentName;
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
67
67
334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392
68 22-Jun spring- By Mr. Varma
public String getStudentNo() {return studentNo;
}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}// action() method is similar to execute()/ handleRequest()public String action() {
System.out.println(".StudentBean.action().START");Service service = ServiceFactory.getService();service.serviceMethod(this);System.out.println(".StudentBean.action().END");return "success";
}}
--Dao.javapackage edu.dao;public interface Dao {
public void daoMethod(Student student);}
--DaoImpl.javapackage edu.dao;public class DaoImpl implements Dao {
public void daoMethod(Student student) {System.out.println(".DaoImpl.daoMethod().START");System.out.println(".Persistance Logic.");System.out.println(".DaoImpl.daoMethod().END");
}}
--ServiceFactory.javapackage edu.factory;public class ServiceFactory {
private static ApplicationContext appContext = new ClassPathXmlApplicationContext(
"applicationContext.xml");private static String SERVICE = "service";public static Service getService() {
return (Service) appContext.getBean(ServiceFactory.SERVICE);}
}
--Service.java
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
68
68
339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443
69 22-Jun spring- By Mr. Varma
package edu.service;public interface Service {
public void serviceMethod(Student student);}
--ServiceImpl.javapackage edu.service;public class ServiceImpl implements Service {
private Dao dao;public void setDao(Dao dao) {
this.dao = dao;}public void serviceMethod(Student student) {
System.out.println(".ServiceImpl.serviceMethod().START");dao.daoMethod(student);System.out.println(".ServiceImpl.serviceMethod().END");
}}
--org.jboss.tools.jst.web.xml<?xml version="1.0" encoding="UTF-8"?><file-systems model-entity="FileSystems" workspace-home="./WebRoot/WEB-INF"> <file-system NAME="WithOutCLL" location="%eclipse.project%" model-entity="FileSystemFolder"/> <file-system NAME="src" location="%workspace.home%/../../src" model-entity="FileSystemFolder"/> <file-system NAME="src-1" location="%workspace.home%/../../config" model-entity="FileSystemFolder"/> <web model-entity="JstWeb"/></file-systems>
--applicationContext.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dao" class="edu.dao.DaoImpl" /><bean id="service" class="edu.service.ServiceImpl">
<property name="dao"><ref bean="dao" />
</property></bean>
</beans>
--faces-config.xml<?xml version='1.0' encoding='UTF-8'?><faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
69
69
344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494
70 22-Jun spring- By Mr. Varma
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2"><managed-bean>
<managed-bean-name>Student</managed-bean-name><managed-bean-class>edu.beans.Student</managed-bean-class><managed-bean-scope>request</managed-bean-scope>
</managed-bean><navigation-rule>
<from-view-id>/student.jsp</from-view-id><navigation-case>
<from-outcome>success</from-outcome><to-view-id>/success.jsp</to-view-id>
</navigation-case></navigation-rule>
</faces-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><servlet>
<servlet-name>FacesServlet</servlet-name><servlet-class>javax.faces.webapp.FacesServlet</servlet-class><load-on-startup>0</load-on-startup>
</servlet><servlet-mapping>
<servlet-name>FacesServlet</servlet-name><url-pattern>*.faces</url-pattern>
</servlet-mapping><welcome-file-list>
<welcome-file>index.jsp</welcome-file></welcome-file-list>
</web-app>
--index.jsp<jsp:forward page="student.faces" />
--student.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
70
70
349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545
71 22-Jun spring- By Mr. Varma
<center><h1>
Student Details</h1>
</center><h:form>
<center><table border="1">
<tr><th>
Student No :</th><td>
<h:inputText value="#{Student.studentNo}" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<h:inputText value="#{Student.studentName}" /></td>
</tr><tr>
<td colspan="2" align="center"><h:commandButton action="#{Student.action}" value="SUBMIT" />
</td></tr>
</table><br>
</center></h:form>
</body></html>
</f:view>
--success.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
71
71
354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596
72 22-Jun spring- By Mr. Varma
</center><center>
<table border="1"><tr>
<th>Student No :
</th><td>
<h:outputText value="#{Student.studentNo}" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<h:outputText value="#{Student.studentName}" /></td>
</tr></table><br>
</center></body>
</html></f:view>
--SpringJSFJPA
--Student.javapackage edu.beans;@Entity@Table(name = "STUDENT", schema = "STUDENT1")public class Student {
private String studentNo;private String studentName;private StudentService studentService;@Id@Column(name = "SNO", unique = true, nullable = false)public String getStudentNo() {
return studentNo;}public void setStudentNo(String studentNo) {
this.studentNo = studentNo;}@Column(name = "SNAME")public String getStudentName() {
return studentName;}public void setStudentName(String studentName) {
this.studentName = studentName;}
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
72
72
359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647
73 22-Jun spring- By Mr. Varma
public void setStudentService(StudentService studentService) {this.studentService = studentService;
}public String action() {
studentService.insertStudent(this);return "success";
}}
--StudentDao.javapackage edu.dao;public interface StudentDao {
public void insertStudent(Student student);}
--StudentDaoImpl.javapackage edu.dao;public class StudentDaoImpl extends JpaDaoSupport implements StudentDao {
public void insertStudent(Student student) {getJpaTemplate().persist(student);
}}
--StudentService.javapackage edu.service;public interface StudentService {
public void insertStudent(Student student);}
--StudentServiceImpl.javapackage edu.service;@Transactionalpublic class StudentServiceImpl implements StudentService {
private StudentDao studentdao;public void setStudentdao(StudentDao studentdao) {
this.studentdao = studentdao;}public void insertStudent(Student student) {
studentdao.insertStudent(student);}
}
--persistence.xml<?xml version="1.0" encoding="UTF-8"?><persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"version="1.0"><persistence-unit name="LocalEntityManagerFactoryBeanPU"
transaction-type="RESOURCE_LOCAL">
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
73
73
364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698
74 22-Jun spring- By Mr. Varma
<provider>org.hibernate.ejb.HibernatePersistence</provider><class>edu.beans.Student</class><properties>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:STUDEV1" />
<property name="hibernate.connection.username" value="STUDENT1" />
<property name="hibernate.connection.password" value="studev1" />
</properties></persistence-unit>
</persistence>
--applicationContext.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
xmlns:tx="http://www.springframework.org/schema/tx"><bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"><property name="persistenceUnitName"
value="LocalEntityManagerFactoryBeanPU" /></bean><bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"><property name="entityManagerFactory"
ref="entityManagerFactory" /></bean><bean id="studentDao" class="edu.dao.StudentDaoImpl">
<property name="entityManagerFactory"><ref bean="entityManagerFactory" />
</property></bean><bean id="studentService" class="edu.service.StudentServiceImpl">
<property name="studentdao"><ref bean="studentDao" />
</property></bean><tx:annotation-driven transaction-manager="transactionManager" />
</beans>
--faces-config.xml<?xml version='1.0' encoding='UTF-8'?>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
74
74
36993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724
372537273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749
75 22-Jun spring- By Mr. Varma
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"version="1.2"><application>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
</application><managed-bean>
<managed-bean-name>Student</managed-bean-name><managed-bean-class>edu.beans.Student</managed-bean-class><managed-bean-scope>request</managed-bean-scope><managed-property>
<property-name>studentService</property-name><value>#{studentService}</value>
</managed-property></managed-bean><navigation-rule>
<from-view-id>/student.jsp</from-view-id><navigation-case>
<from-outcome>success</from-outcome><to-view-id>/success.jsp</to-view-id>
</navigation-case></navigation-rule>
</faces-config>
--web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><context-param>
<param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param><listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener><servlet>
<servlet-name>FacesServlet</servlet-name><servlet-class>javax.faces.webapp.FacesServlet</servlet-class><load-on-startup>0</load-on-startup>
</servlet><servlet-mapping>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
75
75
3750375137523753375437553756
3757375837603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800
76 22-Jun spring- By Mr. Varma
<servlet-name>FacesServlet</servlet-name><url-pattern>*.faces</url-pattern>
</servlet-mapping><welcome-file-list>
<welcome-file>index.jsp</welcome-file></welcome-file-list>
</web-app>
--index.jsp<jsp:forward page="student.faces" />
--student.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>student.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><h:form>
<center><table border="1">
<tr><th>
Student No :</th><td>
<h:inputText value="#{Student.studentNo}" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<h:inputText value="#{Student.studentName}" /></td>
</tr><tr>
<td colspan="2" align="center"><h:commandButton action="#{Student.action}" value="SUBMIT" />
</td></tr>
</table>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
76
76
380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851
77 22-Jun spring- By Mr. Varma
<br></center>
</h:form></body>
</html></f:view>--success.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%><f:view>
<html><head>
<title>success.jsp</title></head><body bgcolor="wheat">
<br><center>
<h1>Student Details
</h1></center><center>
<table border="1"><tr>
<th>Student No :
</th><td>
<h:outputText value="#{Student.studentNo}" /></td>
</tr><tr>
<th>Student Name :
</th><td>
<h:outputText value="#{Student.studentName}" /></td>
</tr></table><br>
</center></body>
</html></f:view>
NARESH I Technologies, Opp.Satyam Theatre,Ameerpet,Hyd. Ph Nos : 23746666 23734842, Email:[email protected], www.nareshit.com
77
77
385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896