0% found this document useful (0 votes)
5 views44 pages

Spring

spring framework
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views44 pages

Spring

spring framework
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

20

012

La
ara
a Te
ech
hnolog
gy
SPR
RING (ORM
(
M & MVC)
M
#102//12,2ndMain
n,5thCross,V
VenkateswaraCollegeRoaad,RamaiahG
Garden,
ChikkaAdugodi,Th
havarakere,B
Bangalore560029.
PhoneNo:08041310124

30/09
9/2012
2
1

LARATECHNOLOGY

LARATECHNOLOGY

Example 1:
[Link]:

package [Link];
publicclassPerson
{
privateintid;
private String firstName;
private String lastName;
privateintage;
publicint getId() {
returnid;
}
publicvoid setId(int id) {
[Link] = id;
}
public String getFirstName() {
returnfirstName;
}
publicvoid setFirstName(String firstName) {
[Link] = firstName;
}
public String getLastName() {
returnlastName;
}
publicvoid setLastName(String lastName) {
[Link] = lastName;
}
publicint getAge() {
returnage;
}
publicvoid setAge(int age) {
[Link] = age;
}
}

2
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link]:
<hibernate-mappingpackage="[Link]">
<classname="Person"table="PERSON">
<idname="id"column="PERSON_ID"/>
<propertyname="firstName"/>
<propertyname="lastName"/>
<propertyname="age"/>
</class>
</hibernate-mapping>

[Link]:
package [Link];
import [Link];
import
import
import
import

[Link];
[Link];
[Link];
[Link];

publicclassManager
{
publicstaticvoid main(String[] args) throws Exception
{
DriverManagerDataSource dmds = new DriverManagerDataSource();
[Link]("[Link]");
[Link]("jdbc:oracle:thin:@localhost:1521:XE");
[Link]("system");
[Link]("great123");
LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();
[Link](dmds);
[Link](newString[]{"com/lara/[Link]"});
Properties props = new Properties();
[Link]("[Link]", "[Link]");
[Link]("hibernate.show_sql", "true");
[Link]("[Link]", "create");
[Link](props);
[Link]();
3
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

HibernateTemplate template = new HibernateTemplate();


[Link]((SessionFactory)[Link]());
[Link]();
Person p1 = new Person();
[Link](100);
[Link]("abc");
[Link]("xyz");
[Link](22);
[Link](p1);
[Link]("done");
}
}
Example 2:

[Link]:

package [Link];
publicclassEmployee
{
privateintid;
private String firstName;
private String lastName;;
private String emailId;
private String designation;
publicint getId() {
returnid;
}
publicvoid setId(int id) {
[Link] = id;
}
public String getFirstName() {
returnfirstName;
}
publicvoid setFirstName(String firstName) {
[Link] = firstName;
}
public String getLastName() {
returnlastName;
}
4
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

publicvoid setLastName(String lastName) {


[Link] = lastName;
}
public String getEmailId() {
returnemailId;
}
publicvoid setEmailId(String emailId) {
[Link] = emailId;
}
public String getDesignation() {
returndesignation;
}
publicvoid setDesignation(String designation) {
[Link] = designation;
}
}
[Link]
<hibernate-mappingpackage="[Link]">
<classname="Employee"table="Employee">
<idname="id"column="PERSON_ID"/>
<propertyname="firstName"/>
<propertyname="lastName"/>
<propertyname="emailId"/>
<propertyname="designation"/>
</class>
</hibernate-mapping>

[Link]:

package [Link];
import [Link];
publicclass EmployeeDAO
{
private HibernateTemplate template;
5
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

publicvoid setTemplate(HibernateTemplate template)


{
[Link] = template;
}
publicvoid save(Employee emp)
{
[Link](emp);
}
public Object load(Integer id)
{
[Link]("[Link]", id);
}
publicvoid update(Employee emp)
{
[Link](emp);
}
}
[Link]:
<beanid="dmds"
class="[Link]">
<propertyname="driverClassName"
value="[Link]"/>
<propertyname="url"
value="jdbc:oracle:thin:@localhost:1521:XE"/>
<propertyname="username"
value="system"/>
<propertyname="password"
value="great123"/>
</bean>
<beanid="mySessionFactory"
class="[Link]">

6
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

<propertyname="dataSource"
ref="dmds"/>
<propertyname="mappingResources">
<list>
<value>com/lara/[Link]</value>
</list>
</property>
<propertyname="hibernateProperties">
<props>
<propkey="[Link]">[Link]</prop>
<propkey="hibernate.show_sql">true</prop>
<propkey="[Link]">create</prop>
</props>
</property>
</bean>
<beanid="hibernateTemplate"
">

class="[Link]
<propertyname="sessionFactory"
ref="mySessionFactory">
</property>
</bean>
<beanid="eDAO"
class="[Link]">
<propertyname="template"
ref="hibernateTemplate"/>
</bean>

[Link]:
7
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

package [Link];
import [Link];
import [Link];
import [Link];
publicclassManager
{
publicstaticvoid main(String[] args)
{
BeanFactory factory = new XmlBeanFactory(new
ClassPathResource("[Link]"));
EmployeeDAO empDAO = (EmployeeDAO)[Link]("pDAO");
Employee emp = new Employee();
[Link](30);
[Link]("pilo");
[Link]("kio");
[Link]("abc@[Link]");
[Link](emp);
[Link]("done");
}
}
Example 3:
[Link]:

package [Link];
publicclassStudent
{
privateintid;
private String firstName;
private String lastName;
privateintage;
publicint getId() {
returnid;
}
publicvoid setId(int id) {
[Link] = id;
}
public String getFirstName() {
returnfirstName;
}
publicvoid setFirstName(String firstName) {
8
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link] = firstName;
}
public String getLastName() {
returnlastName;
}
publicvoid setLastName(String lastName) {
[Link] = lastName;
}
publicint getAge() {
returnage;
}
publicvoid setAge(int age) {
[Link] = age;
}
}
[Link]:

<hibernate-mappingpackage="[Link]">
<classname="Student"table="Student">
<idname="id"column="PERSON_ID"/>
<propertyname="firstName"/>
<propertyname="lastName"/>
<propertyname="age"/>
</class>
</hibernate-mapping>
[Link]:

package [Link];
import [Link];
import [Link];
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];

9
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

publicclass StudentDAO
{
private HibernateTemplate template;
publicvoid setTemplate(HibernateTemplate template)
{
[Link] = template;
}
publicvoid save(Student s)
{
[Link](s);
}
public Object load(Integer id)
{
[Link]([Link], id);
}
public List<Student> read()
{
HibernateCallback action = new HibernateCallback()
{
@Override
public Object doInHibernate(Session arg0)
throws HibernateException,SQLException
{
Criteria ctr =
[Link]([Link]);
List<Student> list = [Link]();
return list;
}
};
return (List<Student>)[Link](action);
}
}
[Link]:

<beanid="dmds"

10
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

class="[Link]">
<propertyname="driverClassName"
value="[Link]"/>
<propertyname="url"
value="jdbc:oracle:thin:@localhost:1521:XE"/>
<propertyname="username"
value="system"/>
<propertyname="password"
value="great123"/>
</bean>
<beanid="mySessionFactory"
class="[Link]">
<propertyname="dataSource"
ref="dmds"/>
<propertyname="mappingResources">
<list>
<value>com/lara/[Link]</value>
</list>
</property>
<propertyname="hibernateProperties">
<props>
<propkey="[Link]">[Link]</prop>
<propkey="hibernate.show_sql">true</prop>
<propkey="[Link]">create</prop>
11
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

</props>
</property>
</bean>
<beanid="hibernateTemplate"
class="[Link]">
<propertyname="sessionFactory"
ref="mySessionFactory">
</property>
</bean>
<beanid="sDAO"
class="[Link]">
<propertyname="template"
ref="hibernateTemplate"/>
</bean>
[Link]:

package [Link];
import [Link];
import [Link];
import [Link];
publicclass Manager
{
publicstaticvoid main(String[] args)
{
BeanFactory factory = new XmlBeanFactory(new
ClassPathResource("[Link]"));
StudentDAO sDAo = (StudentDAO)[Link]("sDAO");
Student s1 = new Student();
[Link](13);
[Link]("abc");
[Link]("xyz");
[Link](22);
[Link](s1);
12
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link]("done");
}
}

Spring Web MVC


Example 1:
[Link]:
<servlet>
<servlet-name>controller</servlet-name>
<servlet-class>
[Link]
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

[Link]:
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<prop key="[Link]">hello</prop>
</props>
</property>
</bean>
[Link]:
<a href="[Link]">call to Spring</a>
13
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link]:
<bean id="hello"
class="[Link]"/>

[Link]:
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
publicclass HelloController implements Controller
{
@Override
publicModelAndView handleRequest(
HttpServletRequest arg0,
HttpServletResponse arg1)
throws Exception
{
[Link]("handleRequest");
ModelAndView mav = new ModelAndView("[Link]");
}

return mav;

[Link]:
Hello to All

Example 2:
[Link]:

<formaction="[Link]">
14
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

Parameter1:
<inputtype="text"
name="param1"><br/>
Parameter2:
<inputtype="text"
name="param2"><br/>
<inputtype="submit"
value="Submit">
</form>

[Link]:

<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<prop key="[Link]">test</prop>
</props>
</property>
</bean>

[Link]:
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
publicclass TestController implements Controller
{
@Override
public ModelAndView handleRequest(
HttpServletRequest arg0,
HttpServletResponse arg1)
15
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

throws Exception
{
String s1 =
[Link]("param1");
String s2 =
[Link]("param2");
[Link](s1);
[Link](s2);
ModelAndView mav = new ModelAndView("[Link]");
return mav;
}
}
[Link]:
This is From [Link] Page

[Link]:
<bean id="test"
class="[Link]"/>

Example 3:
[Link]:
<formaction="[Link]">
${msg}</br>
UserName:
<inputtype="text"
name="username"><br/>
Password:
<inputtype="password"
name="password"><br/>
<inputtype="submit"
value="Submit">
</form>
16
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link]:
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<prop key="[Link]">login</prop>
</props>
</property>
</bean>
<bean id="login"
class="[Link]"/>

[Link]:
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
publicclass LoginController implements Controller
{
@Override
public ModelAndView handleRequest(
HttpServletRequest arg0,
HttpServletResponse arg1)
throws Exception
{
String un =
[Link]("username");
String pw =
[Link]("password");
ModelAndView mav =
new ModelAndView();
17
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

if("lara".equals(un) &&
"rst".equals(pw))
{
[Link]("msg", "Login page is very success");
[Link]("[Link]");
}
else
{
[Link]("msg", "The UserName or Password
Which you have entered is Wrong Pls Try Again");
[Link]("[Link]");
}
return mav;
}
}
[Link]:

${msg}<br/>

Example 4:
[Link]:
${msg}
<formaction="[Link]">
First Name:
<inputtype='text'
name='firstName'/></br>
Last Name:
<inputtype='text'
name='lastName'/></br>
<inputtype='submit'
value='submit'/>
</form>

[Link]:
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
18
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

<props>
<prop key="[Link]">registration</prop>
</props>
</bean>

</property>

<bean id="registration"
class="[Link]"/>

[Link]:
package [Link];
import [Link];
[Link];
import [Link];
import [Link];
publicclass RegistrationController implements Controller
{
@Override
public ModelAndView handleRequest(
HttpServletRequest arg0,
HttpServletResponse arg1)
throws Exception
{
String fName =
[Link]("firstName");
String lName =
[Link]("lastName");
[Link](fName);
[Link](lName);
ModelAndView mav =
new ModelAndView();
19
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link]("obj1", fName);
[Link]("obj2", lName);
[Link]("[Link]");
return mav;
}
}
[Link]:

${obj1}</br>
${obj2}</br>

Example 5:
[Link]:
<servlet>
<servlet-name>controller</servlet-name>
<servlet-class>
[Link]
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
[Link]
</listener-class>
</listener>

[Link]:
<beanid="messageSource"
>

class="[Link]"

<propertyname="basename"value="messages"/>
20
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

</bean>

[Link](develop one properties file in src folder)

[Link]:
<a href="[Link]">Login</a></br>
<a href="[Link]">Registraion</a></br>

[Link]:
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<propkey="[Link]">loginSettings</prop>
</props>
</property>
</bean>
<beanid="loginSettings"
class="[Link]">
<propertyname="formView"
value="[Link]"/>
<propertyname="commandClass"
value="[Link]"/>
<propertyname="commandName"
value="loginForm"/>
<propertyname="validator"
ref="loginValidator"/>
</bean>
<beanid="loginValidator"
class="[Link]"/>
[Link]:
<%@taglibprefix="c"
uri="[Link]
<%@taglibprefix="f"
uri="[Link]
<f:formcommandName="loginForm">
21
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

<c:messagecode="[Link]"/>
<c:bindpath="[Link]">
<inputtype='text'
name='username'
value='${[Link]}'/>
${[Link] }
</c:bind></br>
<c:messagecode="[Link]"/>
<c:bindpath="[Link]">
<inputtype='password'
name='password'
value='${[Link]}'/>
${[Link] }
</c:bind></br>
<inputtype='submit'value='submit'/>
</f:form>

[Link]:
[Link]=Username
[Link]=Password
[Link]:
package [Link];
publicclass LoginForm
{
private String username;
private String password;
public String getUsername() {
returnusername;
}
publicvoid setUsername(String username) {
[Link] = username;
}
public String getPassword() {
returnpassword;
}
publicvoid setPassword(String password) {
[Link] = password;
}
}
[Link]:
22
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

package [Link];
import [Link];
import [Link];
publicclass LoginValidator implements Validator
{
@Override
publicboolean supports(Class arg0)
{
return [Link]([Link]);
}
@Override
publicvoid validate(Object arg0,
Errors arg1)
{
LoginForm login = (LoginForm) arg0;
String s1 = [Link]();
if(s1 == null || [Link]() == 0)
{
[Link]("username",
"[Link]", "Username is mandatory");
}
String s2 = [Link]();
if(s2 == null || [Link]() == 0)
{
[Link]("password",
"[Link]", "Password is mandatory");
}
}
}
[Link]:
package [Link];
import [Link];
import [Link];
publicclass LoginController extends SimpleFormController
{
@Override
protected ModelAndView onSubmit(
Object command)
throws Exception
{
23
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

LoginForm login =
(LoginForm) command;
String un = [Link]();
String pw = [Link]();
ModelAndView mav =
new ModelAndView();
[Link]("username", un);
[Link]("password", pw);
[Link]("[Link]");
return mav;
}
}
[Link]:
${username}</br>
${password}</br>

Example 6:
[Link]
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<propkey="[Link]">regSettings</prop>
</props>
</property>
</bean>
<beanid="regSettings"
class="[Link]">
<propertyname="formView"
value="[Link]"/>
<propertyname="commandClass"
value="[Link]"/>
<propertyname="commandName"
value="regForm"/>
<propertyname="validator"
ref="regValidator"/>
24
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

</bean>
<beanid="regValidator"
class="[Link]"/>

[Link]:
<%@taglibprefix="c"
uri="[Link]
<%@taglibprefix="f"
uri="[Link]
<f:formcommandName="regForm">
<c:messagecode="firstName"/>
<c:bindpath="[Link]">
<inputtype='text'
name='firstName'
value='${[Link]}'/>
${[Link]}
</c:bind></br>
<c:messagecode="lastName"/>
<c:bindpath="[Link]">
<inputtype='text'
name='lastName'
value='${[Link]}'/>
${[Link]}
</c:bind></br>
<inputtype='submit'value='submit'/>
</f:form>

[Link]:
firstName=FirstName
lastName=LastName

[Link]:
package [Link];
publicclass RegForm
{
private String firstName;
private String lastName;
public String getFirstName() {
returnfirstName;
}
publicvoid setFirstName(String firstName) {
[Link] = firstName;
}
25
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

public String getLastName() {


returnlastName;
}
publicvoid setLastName(String lastName) {
[Link] = lastName;
}
}
[Link]:
package [Link];
import [Link];
import [Link];
publicclass RegValidator implements Validator
{
@Override
publicboolean supports(Class arg0)
{
return [Link]([Link]);
}
@Override
publicvoid validate(Object arg0,
Errors arg1)
{
RegForm reg = (RegForm) arg0;
String fName = [Link]();
if(fName == null || [Link]() == 0)
{
[Link]("firstName", "[Link]", "First Name
is mandatory");
}
String lName = [Link]();
if(lName == null || [Link]() == 0)
{
[Link]("lastName", "[Link]", "Last Name
is mandatory");
}
}
}
[Link]:
26
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

package [Link];
import [Link];
import [Link];
publicclass RegistrationController extends SimpleFormController
{
@Override
protected ModelAndView onSubmit(
Object command)
throws Exception
{
RegForm reg = (RegForm) command;
[Link]([Link]());
[Link]([Link]());
ModelAndView mav =
new ModelAndView();
[Link]("[Link]");
return mav;
}
}
[Link]:
success

Example 7:
[Link]:

<servlet>
<servlet-name>application</servlet-name>
<servlet-class>
[Link]
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>application</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<listener>

<listener-class>
[Link]
</listener-class>

27
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

</listener>

[Link]:
<beanid="messageSource"
class="[Link]"
>
<propertyname="basename"
value="[Link]"/>
</bean>

[Link](develop one properties file in src/app folder)


WebContent:
[Link]:
<ahref='[Link]'>Test Request</a></br>
<ahref='[Link]'>Add</a></br>
<ahref="[Link]?abc=add">Adding</a><br>
<ahref="[Link]?abc=list">List</a><br>
<ahref="[Link]?abc=delete">Delete</a><br>
<ahref="[Link]">Registration</a></br>
[Link]
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<propkey="[Link]">testSettings</prop>
</props>
28
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

</property>
</bean>
<beanid="testSettings"
class="[Link]">
<propertyname="formView"
value="test"/>
<propertyname="commandClass"
value="[Link]"/>
<propertyname="commandName"
value="testForm"/>
<propertyname="validator"
ref="testValidator"/>
</bean>
<beanid="testValidator"
class="[Link]"/>
<beanid="viewResolver"
class="[Link]">
<propertyname="viewClass"
value="[Link]"/>
<propertyname="prefix"
value="/WEB-INF/jsp/"/>
<propertyname="suffix"
value=".jsp"/>
</bean>
<beanid="ex-maps"
class="[Link]
olver">
<propertyname="exceptionMappings">
<props>
<propkey="[Link]">
error
</prop>
<propkey="[Link]">
error1
</prop>
</props>
</property>
</bean>
<beanid="multipartResolver"
lver">

class="[Link]

<propertyname="maxUploadSize"
value="100000"/>
29
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

</bean>
WEB-INF(jsp):
[Link]:
from [Link]</br>
${exception}
[Link]:
from [Link]</br>
${exception}
[Link]:
<%@taglibprefix="core"
uri="[Link]
<%@taglibprefix="form"
uri="[Link]
<core:messagecode="title"/>
<form:formcommandName="testForm"enctype="multipart/form-data">
<core:messagecode="param1"/>
<core:bindpath="testForm.param1">
<inputtype='text'
name='param1'
value='${[Link]}'/>
${[Link]}
</core:bind></br>
<core:messagecode="param2"/>
<core:bindpath="testForm.param2">
<inputtype='text'
name='param2'
value='${[Link]}'/>
${[Link]}
</core:bind></br>
<core:messagecode="resume"/>
<core:bindpath="[Link]">
<inputtype='file'
name='resume'
value='${[Link]}'/>
${[Link]}
</core:bind></br>
30
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

<inputtype='submit'value='submit'/>
</form:form>
[Link]:
title=TestApplication
param1=Parameter1
param2=Parameter2
resume=Resume
[Link]:
package [Link];
import [Link];
publicclass TestForm
{
private String param1;
private String param2;
private MultipartFile resume;

publicMultipartFile getResume() {
returnresume;
}
publicvoid setResume(MultipartFile resume) {
[Link] = resume;
}
public String getParam1() {
returnparam1;
}
publicvoid setParam1(String param1) {
this.param1 = param1;
}
public String getParam2() {
returnparam2;
}
publicvoid setParam2(String param2) {
this.param2 = param2;
}
31
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

}
[Link]:
package [Link];
import [Link];
import [Link];
import [Link];
publicclass TestValidator implements Validator
{
@Override
publicboolean supports(Class arg0)
{
return [Link]([Link]);
}
@Override
publicvoid validate(Object arg0,
Errors arg1)
{
TestForm test = (TestForm) arg0;
String p1 = test.getParam1();
if(p1 == null || [Link]() == 0)
{
[Link]("param1", "[Link]", "");
}
String p2 = test.getParam2();
if(p2 == null || [Link]() == 0)
{
[Link]("param2", "[Link]", "");
}
MultipartFile f1 = [Link]();
String fileName = [Link]();
if(fileName == null || [Link]() == 0)
{
[Link]("resume", "[Link]", "");
}
}
}
[Link]:
32
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link]=Parameter1isrequiredone.
[Link]=Parameter2isrequiredone.
[Link]=Resumeisrequiredone.

[Link]:
package [Link];
import [Link];
import [Link];
import [Link];
publicclass TestController extends SimpleFormController
{
@Override
protected ModelAndView onSubmit(
Object command)
throws Exception
{
TestForm test = (TestForm) command;
String p1 = test.getParam1();
String p2 = test.getParam2();
[Link](p1);
[Link](p2);
MultipartFile resume =
[Link]();
byte x[] = [Link]();
[Link]([Link]);
ModelAndView mav =
new ModelAndView();
[Link]("success");
return mav;
}

[Link]:
This is a success</br>
<ahref='[Link]'>Again</a>
33
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

Example 8:
[Link]
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<propkey="[Link]">addSettings</prop>
</props>
</property>
</bean>
<beanid="addSettings"
class="[Link]">
<propertyname="formView"
value="add"/>
<propertyname="commandClass"
value="[Link]"/>
<propertyname="commandName"
value="addForm"/>
</bean>
[Link]
<%@taglibprefix="c"
uri="[Link]
<%@taglibprefix="core"
uri="[Link]
<%@taglibprefix="form"
uri="[Link]
<form:formcommandName="addForm">
First Name:
<core:bindpath="[Link]">
<inputtype='text'
name='firstName'
value='${[Link]}'/>
</core:bind></br>
Last Name:
<core:bindpath="[Link]">
<inputtype='text'
34
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

name='lastName'
value='${[Link]}'/>
</core:bind></br>
Skills:
<core:bindpath="[Link]">
<c:forEachitems="${skills}"
var="skill">
<inputtype='checkbox'
name='skills'
value='${skill}'/>
${skill} &nbsp;&nbsp;
</c:forEach>
</core:bind></br>
<inputtype='submit'
value='submit'/>
</form:form>
[Link]:
package [Link];
publicclass AddForm
{
private String firstName;
private String lastName;
private String skills[];
public String getFirstName() {
returnfirstName;
}
publicvoid setFirstName(String firstName) {
[Link] = firstName;
}
public String getLastName() {
returnlastName;
}
publicvoid setLastName(String lastName) {
[Link] = lastName;
}
public String[] getSkills() {
returnskills;
}
publicvoid setSkills(String[] skills) {
[Link] = skills;
}
35
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

}
[Link]:
package [Link];
import
import
import
import

[Link];
[Link];
[Link];
[Link];

import [Link];
import [Link];
import [Link];
publicclass AddController extends SimpleFormController
{
@Override
protected Map referenceData(HttpServletRequest request)
throws Exception
{
[Link]("referenceData");
Map map = new HashMap();
ArrayList list =
new ArrayList();
[Link]("C");
[Link]("C++");
[Link]("Java");
[Link]("Oracle");
[Link]("skills", list);
return map;
}
@Override
protected Object formBackingObject(
HttpServletRequest request)
throws Exception
{
[Link]("formBackingObject");
AddForm form = new AddForm();
[Link]("abc");
return form;
}
@Override
protected ModelAndView onSubmit(
36
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

Object command)
throws Exception
{
[Link]("onsubmit");
AddForm add = (AddForm) command;
[Link]([Link]());
[Link]([Link]());
[Link]([Link]([Link]()));
returnnew ModelAndView("success");
}
}
[Link]:
This is a success</br>
<ahref='[Link]'>Again</a>
Example 9:
[Link]:
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<propkey="[Link]">helloSettings</prop>
</props>
</property>
</bean>
<beanid="helloSettings"
class="[Link]">
<propertyname="methodNameResolver"
ref="paramResolver"/>
</bean>
<beanid="paramResolver"
class="[Link]
ameResolver">
<propertyname="paramName"
value="abc"/>
</bean>
37
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link]:
package [Link];
import [Link];
import [Link];
import [Link];
import
[Link];
publicclass HelloController extends MultiActionController
{
public ModelAndView add(HttpServletRequest arg0,
HttpServletResponse arg1)
throws Exception
{
ModelAndView mav =
new ModelAndView("success");
[Link]("type","add");
[Link]("add called");
return mav;
}
public ModelAndView list(HttpServletRequest arg0,
HttpServletResponse arg1)
throws Exception
{
ModelAndView mav =
new ModelAndView("success");
[Link]("type","list");
[Link]("list called");
returnmav;
}
public ModelAndView delete(HttpServletRequest arg0,
HttpServletResponse arg1)
throws Exception
{
ModelAndView mav =
new ModelAndView("success");
[Link]("type","delete");
[Link]("delete called");
return mav;
}
}
38
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link]:
This is a success</br>
<ahref='[Link]'>Again</a>

Example 9:
[Link]
<beanid="urlMapping"
class="[Link]">
<propertyname="mappings">
<props>
<propkey="[Link]">regSettings</prop>
</props>
</property>
</bean>
<beanid="regSettings"
class="[Link]">
<propertyname="commandClass"
value="[Link]"/>
<propertyname="commandName"
value="registrationForm"/>
<propertyname="pages">
<list>
<value>reg0</value>
<value>reg1</value>
</list>
</property>
<propertyname="sessionForm"
value="true"/>
</bean>
WEB-INF(jsp folder):
[Link]:
<%@taglibprefix="core"
uri="[Link]
<%@taglibprefix="form"
39
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

uri="[Link]
<form:formcommandName="registrationForm">
First Name:
<core:bindpath="[Link]">
<inputtype='text'
name='firstName'
value='${[Link]}'/>
${[Link]}
</core:bind></br>
Last Name:
<core:bindpath="[Link]">
<inputtype='text'
name='lastName'
value='${[Link]}'/>
${[Link]}
</core:bind></br>
<inputtype="submit"
value="Submit"
name="_target1">
</form:form>
WEB-INF(jsp folder):
[Link]:
<%@taglibprefix="core"
uri="[Link]
<%@taglibprefix="form"
uri="[Link]
<form:formcommandName="registrationForm">
Age:
<core:bindpath="[Link]">
<inputtype='text'
name='age'
value='${[Link]}'/>
${[Link]}
</core:bind></br>
Email:
<core:bindpath="[Link]">
<inputtype='text'
name='email'
value='${[Link]}'/>
${[Link]}
</core:bind></br>
40
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

<inputtype="submit"
value="Submit"
name="_finish">
</form:form>
[Link]:
package [Link];
publicclass RegistrationForm
{
private String firstName;
private String lastName;
privateintage;
private String email;
public String getFirstName() {
returnfirstName;
}
publicvoid setFirstName(String firstName) {
[Link] = firstName;
}
public String getLastName() {
returnlastName;
}
publicvoid setLastName(String lastName) {
[Link] = lastName;
}
publicint getAge() {
returnage;
}
publicvoid setAge(int age) {
[Link] = age;
}
public String getEmail() {
returnemail;
}
publicvoid setEmail(String email) {
[Link] = email;
}
}
[Link]:
41
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

package [Link];
import [Link];
import [Link];
import
import
import
import

[Link];
[Link];
[Link];
[Link];

publicclass RegistrationController extends AbstractWizardFormController


{
@Override
protected ModelAndView processFinish(
HttpServletRequest arg0,
HttpServletResponse arg1,
Object arg2,
BindException arg3)
throws Exception
{
RegistrationForm reg =
(RegistrationForm) arg2;
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
returnnew ModelAndView("success");
}
@Override
protectedvoid validatePage(Object command,
Errors errors,
int page)
{
RegistrationForm reg =
(RegistrationForm) command;
if(page == 0)
{
String fn = [Link]();
if(fn == null ||
[Link]() == 0)
{
[Link]("firstName", "", "First Name is
Mandatory");
}
String ln = [Link]();
if(ln == null ||
42
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

[Link]() == 0)
{
Mandatory");

[Link]("lastName", "", "Last Name is

}
}
if(page == 1)
{
int age = [Link]();
if(age == 0 ||
[Link](age).length() == 0)
{
[Link]("age", "", "Age is Mandatory");
}
String email = [Link]();
if(email == null ||
[Link]() == 0)
{
[Link]("email", "", "Email is
Mandatory");
}
}
}
}
[Link]:
This is a success</br>
<ahref='[Link]'>Again</a>
Example 10:
[Link]:
msg=This is From Default Bundle
messageResources_aus_AUS.properties:
msg=This is From Aus Bundle
messageResources_en_UK.properties:
msg=This is From UK Bundle
messageResources_fr_FR.properties:
43
[Link].com08041310124

LARATECHNOLOGY

LARATECHNOLOGY

msg=This is From French Bundle


[Link]:
package [Link];
import [Link];
import [Link];
import [Link];
publicclass I18N
{
publicstaticvoid main(String[] args)
{
String country = null;
String language = null;
Scanner sc = new Scanner([Link]);
[Link]("Please Enter Language code:");
language = [Link]();
[Link]("Please Enter Country code:");
country = [Link]();
Locale locale = new Locale(language, country);
ResourceBundle rb = null;
rb = [Link]("messageResources", locale);
String message = [Link]("msg");
[Link](message);
}
}

44
[Link].com08041310124

You might also like