This section provides you a brief overview of an online test sample application developed in Spring 3 MVC framework of java.
Spring 3 MVC Online Test Application
This section provides you a brief overview of an online test sample application developed in Spring 3 MVC framework of java. To develop this sample application, we incorporate the Spring 3 MVC with Hibernate 3. Here, you can also download source code of this application given at the end of this article.
Tools & technologies
Tools & technologies used in this project is given below :
Platform |
Windows |
Language | Java |
Tools | Eclipse, SQLyog. |
Technology | Spring 3, Hibernate 3 |
Server | Tomcat 6 |
Backend | MySql |
The directory structure of application
Jar file used
Application Flow
The first page that will appear to you is :
After this page the application is divided into two sections(click to see flow separately) :
CODES
web.xml(/OnlineQuestion/WebContent/WEB-INF/web.xml)
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/forms/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
dispatcher-servlet.xml(/OnlineQuestion/WebContent/WEB-INF/dispatcher-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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <context:property-placeholder location="classpath:jdbc.properties" /> <context:component-scan base-package="net.devmanuals" /> <tx:annotation-driven transaction-manager="hibernateTransactionManager" /> <mvc:annotation-driven /> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/view/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${database.driver}" /> <property name="url" value="${database.url}" /> <property name="username" value="${database.user}" /> <property name="password" value="${database.password}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> <value>net.devmanuals.model.User</value> <value>net.devmanuals.model.Language</value> <value>net.devmanuals.model.Questions</value> <value>net.devmanuals.model.QuestionOptions</value> <value>net.devmanuals.model.Admin</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> </props> </property> </bean> <bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="/WEB-INF/messages" /> </bean> </beans>
messages.properties (/OnlineQuestion/WebContent/WEB-INF/messages.properties)
This file is used by model classes to display validation error to you.
NotEmpty.userForm.userName=User Name must not be empty. Size.userForm.userName=User Name size must be between 1 and 100. NotEmpty.userForm.userEmail=User Email must not be empty. Size.userForm.userEmail=User Email size must be between 1 and 100. Email.userForm.userEmail=User Email not a well-formed email address. NotEmpty.userForm.password=Password must not be empty. Size.userForm.password=Password size must be between 6 and 20. NotEmpty.userForm.phoneNo=phoneNo must not be Empty. Size.userForm.phoneNo=phoneNo size must be between 10 and 20. NotEmpty.user.userEmail=User Email must not be Empty. NotEmpty.user.password=Password must not be Empty. notMatch.userEmail.and.password=User Email or Password you entered is incorrect. NotEmpty.admin.adminEmail=Admin Email must not be Empty. NotEmpty.admin.password=Password must not be Empty. notMatchEmailAndPassword.admin.adminEmail=Admin Email or Password you entered is incorrect. NotEmpty.addQuestionForm.question=Question must not be Empty. NotEmpty.addQuestionForm.option1=Answer1 must not be Empty. NotEmpty.addQuestionForm.option2=Answer2 must not be Empty. NotEmpty.addQuestionForm.option3=Answer3 must not be Empty. NotEmpty.addQuestionForm.option4=Answer4 must not be Empty.
index.jsp ( /OnlineQuestion/WebContent/index.jsp )
This file is configured as welcome file in web.xml. So this contains the first page you view :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Online Test Application</title> </head> <body> <li><a href="forms/user/userlogin.html">user login</a></li> <li><a href="forms/admin/adminlogin.html">admin login</a></li> </body> </html>
jdbc.properties ( /OnlineQuestion/src/jdbc.properties )
This file is used by hibernate to connect to database :
database.driver=com.mysql.jdbc.Driver database.url=jdbc:mysql://192.168.10.13/onlineexamination_spring database.user=root database.password=root hibernate.dialect=org.hibernate.dialect.MySQL5Dialect hibernate.show_sql=true
Codes of Classes
This applications have 8 packages to manage class files. Their name with their description is given. Click to view the class files contained by each package with their description :
net.devmanuals.service.serviceImpl
Codes of JSPs
To handle/manage view of the application ,WEB-INF's view folder contain following two folders :
The above folders contains the JSPs to manage the view of admin and user section. Click above link to see the JSP pages and their description.
[ 0 ] Comments