Login spring mvc with out jdbc database
UserDAO.java
1
2
3
4
5
6
7
8
9
10
11
12
| package com.nrs.spring.dao.dummy;
import com.nrs.spring.dao.UserDAOI;
public class UserDAO implements UserDAOI{
@Override
public boolean findUser(String uname, String pass) {
return (uname.equals("naresh")&&pass.equals("nareshpass"));
}
}
|
UserHome.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| <%@ 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>Insert title here</title>
</head>
<body>
<h1> Hello </h1> ${param.uname }
</body>
</html>
|
LoginForm.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| <!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>Insert title here</title>
</head>
<body>
<form action="login.spring" >
<pre>
UserName : <input type="text" name="uname">
Password : <input type="password" name="pass" >
<input type="submit" value=Login >
</pre>
</form>
</body>
</html>
|
LoginController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| package com.nrs.spring.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.nrs.spring.dao.UserDAOI;
public class LoginController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest req,
HttpServletResponse res) throws Exception {
String uname=req.getParameter("uname");
String pass=req.getParameter("pass");
boolean flag=udao.findUser(uname,pass);
System.out.println(flag);
if(flag){
return new ModelAndView("/UserHome.jsp");
}else{
return new ModelAndView("/LoginForm.html");
}
}
private UserDAOI udao;
public void setUserDAO(UserDAOI udao) {
this.udao = udao;
}
}
|
applicationContext-dao-dummy.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| <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"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="udao" class="com.nrs.spring.dao.dummy.UserDAO" />
</beans>
|
ds-servlet.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
| <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"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="/login.spring" class="com.nrs.spring.web.LoginController" p:UserDAO-ref="udao" />
</beans>
|
web.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| <web-app>
<servlet>
<servlet-name>ds</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/ds-servlet.xml
/WEB-INF/applicationContext-dao-dummy.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ds</servlet-name>
<url-pattern>*.spring</url-pattern>
</servlet-mapping>
</web-app>
|
Output screens:
1
2
3
4
5
6
7 | package com.nrs.spring.dao;
public interface UserDAOI {
boolean findUser(String uname, String pass);
}
|
No comments :
Post a Comment