-
Notifications
You must be signed in to change notification settings - Fork 2
/
Scores.java
112 lines (109 loc) · 4.17 KB
/
Scores.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Scores extends HttpServlet
{
private ConnectionPool pool;
private ServletContext context;
private static String servletName="Scores";
public void init()
{
context = getServletContext();
synchronized(context)
{
pool=(ConnectionPool)context.getAttribute("pool");
if(pool==null)
{
String driverClassName = context.getInitParameter("driverClassName");
String url = context.getInitParameter("url");
String userName = context.getInitParameter("username");
String password = context.getInitParameter("password");
try
{
pool=new ConnectionPool(driverClassName,url,userName,password);
}
catch(Exception error)
{
Routines.writeToLog(servletName,"Unable to create connection pool : " + error,false,context);
}
context.setAttribute("pool",pool);
}
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
{
response.setContentType("text/html");
PrintWriter webPageOutput=null;
try
{
webPageOutput=response.getWriter();
}
catch(IOException error)
{
Routines.writeToLog(servletName,"Error getting writer : " + error,false,context);
}
HttpSession session=request.getSession();
session.setAttribute("redirect",request.getRequestURL() + "?" + request.getQueryString());
Connection database=null;
try
{
database=pool.getConnection(servletName);
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to connect to database : " + error,false,context);
}
Routines.WriteHTMLHead("Scores",//title
true,//showMenu
2,//menuHighLight
true,//seasonsMenu
true,//weeksMenu
true,//scores
false,//standings
false,//gameCenter
false,//schedules
false,//previews
false,//teamCenter
false,//draft
database,//database
request,//request
response,//response
webPageOutput,//webPageOutput
context);//context
//Work out if selected week has been played yet or not.
int viewWeek=Routines.safeParseInt((String)session.getAttribute("viewWeek"));
if (Routines.safeParseInt((String)session.getAttribute("week"))==0)
{
Previews.createScreen(request,
response,
database,
webPageOutput,
context);
}
else
{
int latestSeason=Routines.safeParseInt((String)session.getAttribute("season"));
int latestWeek=Routines.safeParseInt((String)session.getAttribute("week"));
int viewSeason=Routines.safeParseInt((String)session.getAttribute("season"));
if(latestSeason==viewSeason&&latestWeek<viewWeek)
{
Previews.createScreen(request,
response,
database,
webPageOutput,
context);
}
else
{
Results.createScreen(request,
response,
database,
webPageOutput,
context);
}
}
pool.returnConnection(database);
}
}