Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Spring Roo 1.3.0.BUILD-SNAPSHOT [rev 566af23] log opened at 2012-05-09 16:38:26 | ||
version | ||
// [failed] version | ||
version -jaime | ||
// [failed] version -jaime | ||
version jaime | ||
// [failed] version jaime | ||
version jaime | ||
// [failed] version jaime | ||
exit | ||
// Spring Roo 1.3.0.BUILD-SNAPSHOT [rev 566af23] log closed at 2012-05-09 16:40:02 | ||
// Spring Roo 1.3.0.BUILD-SNAPSHOT [rev 566af23] log opened at 2012-05-09 16:40:02 | ||
// [failed] exit | ||
// Spring Roo 1.3.0.BUILD-SNAPSHOT [rev 566af23] log closed at 2012-05-09 16:40:02 | ||
// Spring Roo 1.2.1.RELEASE [rev 6eae723] log opened at 2012-05-09 16:40:12 | ||
version | ||
version jaime | ||
version -jaime | ||
help | ||
version -jaime | ||
version jaime | ||
exit | ||
// Spring Roo 1.2.1.RELEASE [rev 6eae723] log closed at 2012-05-09 16:41:25 | ||
// Spring Roo 1.1.5.RELEASE [rev d3a68c3] log opened at 2012-05-09 16:41:35 | ||
version jaime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.epam.kaka; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
import javax.servlet.http.HttpSessionAttributeListener; | ||
import javax.servlet.http.HttpSessionBindingEvent; | ||
|
||
/** | ||
* Application Lifecycle Listener implementation class MyLostener | ||
* | ||
*/ | ||
public class MyLostener implements ServletContextListener, HttpSessionAttributeListener { | ||
|
||
private int loggedInUsers = 0; | ||
/** | ||
* Default constructor. | ||
*/ | ||
public MyLostener() { | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
/** | ||
* @see HttpSessionAttributeListener#attributeRemoved(HttpSessionBindingEvent) | ||
*/ | ||
public void attributeRemoved(HttpSessionBindingEvent se) { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
/** | ||
* @see HttpSessionAttributeListener#attributeAdded(HttpSessionBindingEvent) | ||
*/ | ||
public void attributeAdded(HttpSessionBindingEvent se) { | ||
if ("username".equals(se.getName())){ | ||
Object user = se.getValue(); | ||
System.out.println(user + "\n###\n###\n### is about to log in"); | ||
System.out.println("\n###\n###\n### logged in users:" + ++loggedInUsers); | ||
} | ||
} | ||
|
||
/** | ||
* @see ServletContextListener#contextInitialized(ServletContextEvent) | ||
*/ | ||
public void contextInitialized(ServletContextEvent sce) { | ||
ServletContext context = sce.getServletContext(); | ||
Map<String,String> users = new HashMap<String,String>(); | ||
users.put("jeno", "pwd"); | ||
users.put("odon", "pwd"); | ||
users.put("valeria", "pwd"); | ||
context.setAttribute("users", users); | ||
} | ||
|
||
/** | ||
* @see HttpSessionAttributeListener#attributeReplaced(HttpSessionBindingEvent) | ||
*/ | ||
public void attributeReplaced(HttpSessionBindingEvent se) { | ||
attributeAdded(se); | ||
} | ||
|
||
/** | ||
* @see ServletContextListener#contextDestroyed(ServletContextEvent) | ||
*/ | ||
public void contextDestroyed(ServletContextEvent sce) { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.lalyos.mvc; | ||
|
||
import java.util.Map; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
|
||
@Controller | ||
public class LoginController { | ||
|
||
@RequestMapping("/login") | ||
public String login(String username, String password, HttpSession session) { | ||
Map<String,String> users = (Map<String, String>) session.getServletContext().getAttribute("users"); | ||
|
||
String origPassword = users.get(username); | ||
if (password != null && password.equals(origPassword)) { | ||
session.setAttribute("username", username); | ||
} | ||
return "redirect:/lunch/list"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
<hr/> | ||
<h1>Footer ...</h1> | ||
<hr/> | ||
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> | ||
<c:url value="/login" var="loginUrl" /> | ||
<form class="well form-inline" action="${loginUrl}"> | ||
<input type="text" name="username" class="input-small" placeholder="Username"> | ||
<input type="password" name="password" class="input-small" placeholder="Password"> | ||
<label class="checkbox"> | ||
<input type="checkbox"> Remember me | ||
</label> | ||
<button type="submit" class="btn">Sign in</button> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,5 +91,8 @@ | |
|
||
|
||
|
||
<listener> | ||
<listener-class>com.epam.kaka.MyLostener</listener-class> | ||
</listener> | ||
|
||
</web-app> |