Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------
- FILE INDEX.HTML
- ----------------------
- <!DOCTYPE html>
- <html lang="it">
- <head>
- <meta charset="UTF-8">
- <title>Cookies</title>
- </head>
- <body>
- <form action="login.jsp" method="post">
- <div>
- <label for="user">Nome Utente</label>
- <input type="text" id="user" name="username" required="required">
- </div>
- <!-- inserisco due <div> per far si che i due elementi siano l'uno sopra l'altro -->
- <div>
- <label for="pass">Password</label>
- <input type="password" id="pass" name= "password" required="required">
- </div>
- <div>
- <input type="submit" value="login">
- </div>
- </form>
- </body>
- </html>
- -----------------
- LOGIN.JSP
- -----------------
- <%@ page session="true"
- import="it.cefi.User" %> <!-- per poter utlizzare dati di sessione all'interno della pagina(di defaut e' true ) -->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Sessions</title>
- </head>
- <body>
- <jsp:useBean id="user" class="it.cefi.User" />
- <jsp:setProperty property="*" name="user"/>
- <%
- if(user.getUsername().equals("danilo")
- && user.getPassword().equals("1234")) {
- session.setAttribute("username", user.getUsername());
- response.sendRedirect("page1.jsp");
- }
- %>
- <h3>Nome Utene o Password non corretti</h3>
- <a href="index.html">Torna Indietro</a>
- </body>
- </html>
- ----------------
- LOGOUT.JSP
- ----------------
- <%@ page session="true"%>
- <%
- if(session.getAttribute("username") != null) {
- session.invalidate();
- }
- response.sendRedirect("Index.html");
- %>
- ----------------
- PAGE1.JSP
- ----------------
- <%@ page session="true"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Sessions</title>
- </head>
- <body>
- <%
- if(session.getAttribute("username") != null) {
- %>
- <h3>Benvenuto, <%= session.getAttribute("username") %></h3>
- <h3>ID di sessione: <%= session.getId() %></h3>
- <a href="logout.jsp">Disconnetti</a>
- <% } else { %>
- <h3>Accesso Non Consentito</h3>
- <a href="index.html">Torna Indietro</a>
- <% } %>
- </body>
- </html>
- ----------------
- USER.JAVA
- ----------------
- package it.cefi;
- import java.io.Serializable;
- public class User implements Serializable {
- private static final long serialVersionUID = 1L;
- private String username; /*dovranno avere lo stesso nome del campo a cui fanno riferimento nella parte web*/
- private String password;
- public User() {
- super();
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement