0% found this document useful (0 votes)
134 views20 pages

Lucrare de Laborator Nr.3: Obiect: Java Pe Calculator

This document contains source code for Java web applications that allow users to add, edit, and delete player records from a database. The code includes Java Server Pages (JSP) files for the user interface and actions, as well as CSS for styling. The main JSP files are for adding, editing/deleting players, and displaying the player index/list. The code uses classes like PlayerBean and PlayerFactory to work with the player data.

Uploaded by

Mihaela Pădure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views20 pages

Lucrare de Laborator Nr.3: Obiect: Java Pe Calculator

This document contains source code for Java web applications that allow users to add, edit, and delete player records from a database. The code includes Java Server Pages (JSP) files for the user interface and actions, as well as CSS for styling. The main JSP files are for adding, editing/deleting players, and displaying the player index/list. The code uses classes like PlayerBean and PlayerFactory to work with the player data.

Uploaded by

Mihaela Pădure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Ministerul Educaiei a Republicii Moldova

Universitatea de Stat din Moldova


Facultatea Matematic si Informatic

Lucrare de laborator Nr.3


Obiect: Java Pe Calculator

Chiinu 2014

Cod sursa:
//Adaugare
1

<%@page import="org.party.com.PlayerBean"%>
<%@page import="org.party.com.PlayerFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
try{
String name = request.getParameter("player-name");
String tip= request.getParameter("player-tip");
int price = Integer.parseInt(request.getParameter("player-price"));
String photo = request.getParameter("player-photo");
if(name.length()==0) throw new Exception();
if(tip.length()==0) throw new Exception();
if(photo.length()==0) throw new Exception();
2

PlayerBean pla = new PlayerBean( name, tip, price,photo);


PlayerFactory.addPlayer(pla);
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", "../index.jsp"); }
catch(Exception ex){
%>Ati introdus o valoare gresita,sau nu ati introdus nimic <% }%>
</body>
</html>
//Editare
<%@page import="org.party.com.PlayerFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title> </head>
<body>
<h1>Edit</h1>
<%
try{
3

int id = Integer.parseInt(request.getParameter("player-id"));
String name = request.getParameter("player-name");
String tip = request.getParameter("player-tip");
int price = Integer.parseInt(request.getParameter("player-price"));
String photo = request.getParameter("player-photo");
%>
<%=id%>
<%response.setStatus(response.SC_MOVED_TEMPORARILY);
if(PlayerFactory.Edit(id, price, name, tip, photo))
response.setHeader("Location", "../index.jsp");
else
response.setHeader("Location", "../index.jsp");
}catch(Exception ex){%>
<%=ex%>
<%}
%>
</body> </html>
//Stergere
<%@page import="org.party.com.PlayerFactory"%>
4

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Delete</h1>
<%
try{
int id = Integer.parseInt(request.getParameter("player-id")); %>
<%=id%>
<%response.setStatus(response.SC_MOVED_TEMPORARILY);
if(PlayerFactory.deletePlayerById(id))
response.setHeader("Location", "../index.jsp");
else
response.setHeader("Location", "../index.jsp");
}catch(Exception ex){%>
5

<%=ex%>
<%}
%>
</body>
</html>
//Adaugare .jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../style.css" type="text/css" />
<title>JSP Page</title>
</head>
<body>
<div id="mainContainer">
<div id="login" class="loginForm">
<div class="login-top">
</div>
6

<h1 align="center">Adaugati o petrecere</h1><br><br>


<form action="../actions/add.jsp" method="GET" class="login-fields">
<label>Name</label> <input type="text" name="player-name"><br>
<label>Tip</label> <input type="text" name="player-tip"<><br>
<label>Price</label> <input type="text" name="player-price" ><br>
<label>Photo</label> <input type="text" name="player-photo" ><br>
<button type="submit">Adauga</button>
</form>
</div>
</div>
</body>
</html>
//Editare-Stergere.jsp
<%@page import="org.party.com.PlayerFactory"%>
<%@page import="org.party.com.PlayerBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
7

<link rel="stylesheet" href="../style.css" type="text/css" />


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Delete Edit</title>
</head>
<body>
<% String Action = "";
String formAction = "";
String enableInputs = "disabled";
PlayerBean foundPlayer = new PlayerBean();
try{
String action = request.getParameter("action");
int id = Integer.parseInt(request.getParameter("id"));
foundPlayer = PlayerFactory.getPlayerById(id);
if(action.equals("delete")){ Action = "Delete";formAction="actions/delete.jsp";
%> <div id="mainContainer">
<div id="login" class="loginForm">
<div class="login-top"> </div>
<h1 align="center">Delete Petrecere</h1>

<%

}else if(action.equals("edit")){ Action =

"Edit";formAction="actions/edit.jsp";enableInputs="";
%>
<div id="mainContainer">
<div id="login" class="loginForm">
<div class="login-top">
</div>

<h1 align="center"> Edit Petrecere</h1>


<%

}else{

%> Unknown action


<%

}catch(Exception ex){
%> error
<%}%>

<form action="../<%=formAction%>" method="GET" class="login-fields">


<input type="hidden" name="player-id" value="<%=foundPlayer.getId()%>"/>
<label>Id</label> <input type="text" name="player-idd" disabled value="<
%=foundPlayer.getId()%>"/><br>
9

<label>Name</label> <input type="text" name="player-name" <%=enableInputs


%> value="<%=foundPlayer.getName()%>"><br>
<label>Tip</label> <input type="text" name="player-tip" <%=enableInputs%>
value="<%=foundPlayer.getTip()%>"><br>
<label>Price</label> <input type="text" name="player-price" <%=enableInputs
%> value="<%=foundPlayer.getPrice()%>"><br>
<label>Photo</label> <input type="text" name="player-photo" <%=enableInputs
%> value="<%=foundPlayer.getPhoto()%>"><br>
<button type="submit"><%=Action%></button>
</form>
</div>
</div>
</body>
</html>
//Index
<%@page import="java.util.ArrayList"%>
<%@page import="org.party.com.PlayerBean"%>
<%@page import="org.party.com.PlayerFactory"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
10

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Laborator 3</title>
</head>
<body>
<div id="page-wrap">
<h1><a href="jsp/add.jsp" class="button-secondary purebutton">Adauga</a></h1>

<table >
<tr>
<td> Id </td>
<td>Name petrecere</td>
<td>Tip Torta</td>
<td>Price</td>
<td>Photo</td>

11

<td>Editeaza</td>
<td>Sterge</td>
</tr>
<tr>
<%
ArrayList<PlayerBean> players = PlayerFactory.players;
if(players.size() > 0)
{
for(PlayerBean player : players){
%>
<td><%= player.getId() %></td>
<td><%=player.getName()%></td>
<td><%=player.getTip()%></td>
<td><%=player.getPrice()%>$</td>
<td><img src="img/<%=player.getPhoto()%>"></td>
<td> <a href="jsp/delete_edit.jsp?action=edit&id=<%= player.getId()
%>"><img src="img/bif.png"></a> </td>
<td>

<a href="jsp/delete_edit.jsp?action=delete&id=<%= player.getId()

%>"><img src="img/delete.png"></a></td>
</tr>
12

<%
}
}else
{
%>
<h1 style="color: red"> nu sunt date!!!</h1>
<%
}%>
</div>
</table>
</body>
</html>
//Css
*{
margin: 0;
padding: 0;
}
body {
13

font: 14px/1.4 Georgia, Serif;


}
#page-wrap {
margin: 50px;
}
p{
margin: 20px 0;
}

/*
Generic Styling, for Desktops/Laptops
*/
table {
width: 100%;
border-collapse: collapse;
}
/* Zebra striping */
tr:nth-of-type(1) {
background: #eee;
14

}
th {
background: #333;
color: white;
font-weight: bold;
}
td, th {
padding: 6px;
border: 1px solid #ccc;
text-align: center;
}
td img{
width:140px;

}
a img{
width: 40px;
}

15

.button-secondary {
color: #2E658C;

border-radius: 4px;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.button-secondary:hover{

color: #1D4059;

a.button-secondary {
text-decoration: none;
}

/*
16

Form la adugare
*/

#mainContainer {
line-height: 20px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
background-color: rgba(0,50,94,0.2);
margin: 20px auto;
display: table;
-moz-border-radius: 15px;
border-style: solid;
border-color: rgb(40, 40, 40);
border-radius: 2px 5px 2px 5px / 5px 2px 5px 2px;
border-radius: 2px;
border-radius: 2px 5px / 5px;
box-shadow: 0 5px 10px 5px rgba(0,0,0,0.2);
}

.loginForm {
17

width: 320px;
height: 400px;
padding: 10px 15px 25px 15px;
overflow: hidden;
}

.login-fields > .login-bottom input#login-button_normal {


float: right;
padding: 2px 25px;
cursor: pointer;
margin-left: 10px;
}

.login-fields > .login-bottom input#login-remember {


float: left;
margin-right: 3px;
}

.spacer {
18

padding-bottom: 10px;
}

/* ELEMENT OF INTEREST HERE! */


input[type=text],
input[type=password] {
width: 100%;
height: 20px;
padding: 5px 10px;
background-color: rgb(215, 215, 215);
line-height: 20px;
font-size: 12px;
color: rgb(136, 136, 136);
border-radius: 2px 2px 2px 2px;
border: 1px solid rgb(114, 114, 114);
box-shadow: 0 1px 0 rgba(24, 24, 24,0.1);
}input[type=text]:hover,
input[type=password]:hover,
label:hover ~ input[type=text],
19

label:hover ~ input[type=password] {
background:rgb(242, 242, 242);
}input[type=submit]:hover {
box-shadow:
inset 0 1px 0 rgba(255,255,255,0.3),
inset 0 -10px 10px rgba(255,255,255,0.1);
}
.login-top {
height: 85px;
}

.login-bottom {
padding: 35px 15px 0 0;
}

20

You might also like