Repository navigation
Expand file tree
/
Copy pathsignUpProcess.jsp
More file actions
212 lines (182 loc) · 7.74 KB
/
Copy pathsignUpProcess.jsp
File metadata and controls
212 lines (182 loc) · 7.74 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<%@page import="java.sql.*"%><%@ page import = "java.io.*,java.util.*, javax.servlet.*" %>
<%@ page import = "javax.servlet.http.*" %>
<%@ page import = "org.apache.commons.fileupload.*" %>
<%@ page import = "org.apache.commons.fileupload.disk.*" %>
<%@ page import = "org.apache.commons.fileupload.servlet.*" %>
<%@ page import = "org.apache.commons.io.output.*" %>
<%
File file ;
int maxFileSize = 5000 * 1024;
int maxMemSize = 5000 * 1024;
String fileName = "";
ServletContext context = pageContext.getServletContext();
String filePath = context.getInitParameter("file-upload");
// Verify the content type
String contentType = request.getContentType();
if ((contentType.indexOf("multipart/form-data") >= 0)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
// maximum size that will be stored in memory
factory.setSizeThreshold(maxMemSize);
// Location to save data that is larger than maxMemSize.
factory.setRepository(new File("c:\\temp"));
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// maximum file size to be uploaded.
upload.setSizeMax( maxFileSize );
try {
// Parse the request to get file items.
List fileItems = upload.parseRequest(request);
// Process the uploaded file items
Iterator i = fileItems.iterator();
out.println("<html>");
out.println("<head>");
out.println("<title>JSP File upload</title>");
out.println("</head>");
out.println("<body>");
while ( i.hasNext () ) {
FileItem fi = (FileItem)i.next();
if ( !fi.isFormField () ) {
// Get the uploaded file parameters
String fieldName = fi.getFieldName();
int dotPos = fi.getName().lastIndexOf(".");
String extn = fi.getName().substring(dotPos, fi.getName().length());
fileName = (String)session.getAttribute("tempEmail")+extn;
boolean isInMemory = fi.isInMemory();
long sizeInBytes = fi.getSize();
// Write the file
if( fileName.lastIndexOf("\\") >= 0 ) {
file = new File( filePath +
fileName.substring( fileName.lastIndexOf("\\"))) ;
} else {
file = new File( filePath +
fileName.substring(fileName.lastIndexOf("\\")+1)) ;
}
fi.write( file ) ;
out.println("Uploaded Filename: " + filePath +
fileName + "<br>");
}
}
out.println("</body>");
out.println("</html>");
} catch(Exception ex) {
System.out.println(ex);
}
} else {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet upload</title>");
out.println("</head>");
out.println("<body>");
out.println("<p>No file uploaded</p>");
out.println("</body>");
out.println("</html>");
}
String name = (String)session.getAttribute("tempName");
String email = (String)session.getAttribute("tempEmail");
String phone = (String)session.getAttribute("tempPhone");
String role = (String)session.getAttribute("tempRole");
String password = (String)session.getAttribute("tempPassword");
String balance = null;
String licenceNo = null;
String experience = null;
String joiningDate = null;
Connection con = null;
Statement st = null;
String query = null;
if(role.equals("Admin"))
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shivajiroadways", "root", "1234");
st = con.createStatement();
query = "insert into Email values('" + email + "')";
st.executeUpdate(query);
query = "insert into admin(email, name, phone, password, profilePic) values('"+email+"', '"+name+"', '"+phone+"', '"+password+"', '"+fileName+"');";
st.executeUpdate(query);
}
catch(Exception e)
{
out.print(e.getMessage());
}
}
if(role.equals("Passanger"))
{
balance = (String)session.getAttribute("tempBalance");
out.print(" account balance: "+balance);
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shivajiroadways", "root", "1234");
st = con.createStatement();
query = "insert into Email values('" + email + "')";
st.executeUpdate(query);
query = "insert into passanger(email, name, phone, password, walletBalance, profilePic) values('"+email+"', '"+name+"', '"+phone+"', '"+password+"', '"+Integer.parseInt(balance)+"', '"+fileName+"');";
st.executeUpdate(query);
}
catch(Exception e)
{
out.print(e.getMessage());
}
}
if(role.equals("Driver"))
{
licenceNo = (String)session.getAttribute("tempLicenceNo");
experience = (String)session.getAttribute("tempExperience");
joiningDate = (String)session.getAttribute("tempJoiningDate");
out.print(" licenceNo: "+licenceNo+" experience: "+experience+" joiningDate: "+joiningDate);
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shivajiroadways", "root", "1234");
st = con.createStatement();
query = "insert into Email values('" + email + "')";
st.executeUpdate(query);
query = "insert into driver(email, name, phone, password, licenceNo, experience, dob, profilePic) values('"+email+"', '"+name+"', '"+phone+"', '"+password+"', '"+licenceNo+"', '"+Integer.parseInt(experience)+"', '"+joiningDate+"', '"+fileName+"');";
st.executeUpdate(query);
}
catch(Exception e)
{
out.print(e.getMessage());
}
}
if(role.equals("Conductor"))
{
joiningDate = (String)session.getAttribute("tempJoiningDate");
out.print(" joiningDate: "+joiningDate);
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shivajiroadways", "root", "1234");
st = con.createStatement();
query = "insert into Email values('" + email + "')";
st.executeUpdate(query);
query = "insert into conductor(email, name, phone, password, dob, profilePic) values('"+email+"', '"+name+"', '"+phone+"', '"+password+"', '"+joiningDate+"', '"+fileName+"');";
st.executeUpdate(query);
}
catch(Exception e)
{
out.print(e.getMessage());
}
}
if(role.equals("Ticket Checker"))
{
joiningDate = (String)session.getAttribute("tempJoiningDate");
out.print(" joiningDate: "+joiningDate);
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shivajiroadways", "root", "1234");
st = con.createStatement();
query = "insert into Email values('" + email + "')";
st.executeUpdate(query);
query = "insert into ticketchecker(email, name, phone, password, dob, profilePic) values('"+email+"', '"+name+"', '"+phone+"', '"+password+"', '"+joiningDate+"', '"+fileName+"');";
st.executeUpdate(query);
}
catch(Exception e)
{
out.print(e.getMessage());
}
}
response.sendRedirect("registerdSuccessfully.jsp");
%>