-
-
Save JaS4083/9934647db3b9601ae5daacc4a4e2781a to your computer and use it in GitHub Desktop.
Java Bean Example
This file contains hidden or 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
package model; | |
import java.util.List; | |
public class Customer { | |
private String name; | |
private String email; | |
private String password; | |
private String[] qoute; | |
private boolean isAdmin; | |
public String[] getQoute() { | |
return qoute; | |
} | |
public String getQoute(int index){ | |
return this.qoute[index]; | |
} | |
public void setQoute(String[] qoute) { | |
this.qoute = qoute; | |
} | |
public void setQoute(int index,String qoute){ | |
this.qoute[index] = qoute; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getEmail() { | |
return email; | |
} | |
public void setEmail(String email) { | |
this.email = email; | |
} | |
public String getPassword() { | |
return password; | |
} | |
public void setPassword(String password) { | |
this.password = password; | |
} | |
public boolean isIsAdmin() { | |
return isAdmin; | |
} | |
public void setIsAdmin(boolean isAdmin) { | |
this.isAdmin = isAdmin; | |
} | |
} |
This file contains hidden or 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
package controller.customer; | |
import java.io.IOException; | |
import javax.servlet.ServletException; | |
import javax.servlet.annotation.WebServlet; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
@WebServlet(name = "CustomerController", urlPatterns = {"/customer"}) | |
public class CustomerController extends HttpServlet { | |
@Override | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) | |
throws ServletException, IOException { | |
request.getServletContext().getRequestDispatcher("/WEB-INF/customer/index.jsp").forward(request,response); | |
} | |
@Override | |
protected void doPost(HttpServletRequest request, HttpServletResponse response) | |
throws ServletException, IOException { | |
request.getServletContext().getRequestDispatcher("/WEB-INF/customer/process.jsp").forward(request, response); | |
} | |
} |
This file contains hidden or 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
<form action="${pageContext.request.contextPath}/customer" method="POST"> | |
<input type="text" name="name" placeholder="Your name"/> | |
<input type="text" name="email" placeholder="email"/> | |
<input type="password" name="password" placeholder="password"/> | |
isAdmin : <input type="radio" name="isAdmin" value="true"/>Yes | |
<input type="radio" name="isAdmin" value="false"/>No<br/> | |
<input type="test" name="qoute" placeholder="Qoute 1"/> | |
<input type="test" name="qoute" placeholder="Qoute 2"/> | |
<input type="test" name="qoute" placeholder="Qoute 3"/> | |
<button>Submit</button> | |
</form> |
This file contains hidden or 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
<%@page contentType="text/html" pageEncoding="UTF-8"%> | |
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> | |
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> | |
<jsp:useBean id="cust" class="model.Customer"/> | |
<jsp:setProperty name="cust" property="*"/> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>JSP Page</title> | |
</head> | |
<body> | |
<h1>Hello, ${cust.name}</h1> | |
Your email is ${cust.email}<br/> | |
You is ${cust.isAdmin ? "" : "not"} Admin | |
<pre><c:forEach var="i" begin="0" end="${fn:length(cust.qoute)-1}">${cust.qoute[i]}<br></c:forEach></pre> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment