-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue.jsp
196 lines (164 loc) · 6.11 KB
/
issue.jsp
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
<%@ page import="java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="java.util.Date" %>
<script type = "text/javascript" >
function disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()", 0);
</script>
<%
String userid = request.getParameter("userid");
String id0 = request.getParameter("bookname1");
String id1 = request.getParameter("bookname2");
String id2 = request.getParameter("bookname3");
String id3 = request.getParameter("bookname4");
String idj[] = new String[4];
idj[1] = request.getParameter("bookname2");
idj[2] = request.getParameter("bookname3");
idj[3] = request.getParameter("bookname4");
java.util.Date now = new java.util.Date();
String DATE_FORMAT = "dd-MM-yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
String strDateNew = sdf.format(now) ;
//out.println("Book One:"+idj[1]+"IS");
//out.println(idj[2]);
//out.println(idj[3]);
int i=1;
for(int j=1;j<=3;j++)
{
if(idj[j]==null || idj[j]=="" )
{
}
else if(idj[j] != null || idj[j]!="")
{
out.println("Book Is :"+idj[j]+"....");
i++;
}
}
out.println("No. of Books Are:"+i);
Date currentDate = new Date();
//System.out.println(sdf.format(currentDate));
// convert date to calendar
Calendar c = Calendar.getInstance();
c.setTime(currentDate);
// manipulate date
c.add(Calendar.DATE, 15);
// convert calendar to date
Date currentDatePlusOne = c.getTime();
//out.println(sdf.format(currentDatePlusOne));
String dates = sdf.format(currentDatePlusOne);
String flag = request.getParameter("flag");
PreparedStatement pstmt;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/login", "root", "");
pstmt=con.prepareStatement("Insert into transaction(userid,id0,id1,id2,id3,issue_date,return_date,flag) values(?,?,?,?,?,?,?,?)");
pstmt.setString(1,userid);
pstmt.setString(2,id0);
pstmt.setString(3,id1);
pstmt.setString(4,id2);
pstmt.setString(5,id3);
pstmt.setString(6,strDateNew);
pstmt.setString(7,dates);
pstmt.setString(8,flag);
pstmt.executeUpdate();
String id[] = new String[4];
id[0] = id0;
id[1] = id1;
id[2] = id2;
id[3] = id3;
String book[] =new String[4];
String bookname[] = new String[4];
String authorname[] = new String[4];
int ii=0;
for(ii=0;ii<i;ii++)
{
book[ii] = id[ii];
Class.forName("com.mysql.jdbc.Driver");
// Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1/login", "root", "");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from books where id='" + book[ii] + "'");
if (rs.next()) {
bookname[ii] = rs.getString("bookname");
authorname[ii] = rs.getString("authorname");
out.println(book[ii]);
out.println(bookname[ii]);
out.println(authorname[ii]);
}
}
//Creating a result for getting status that messsage is delivered or not!
String result;
String total = new String();
for(int j1=0;j1<i;j1++)
{
total = total + bookname[j1]+" by "+authorname[j1]+"\n";
}
out.println("Total "+total);
// Get recipient's email-ID, message & subject-line from index.html page
final String to = request.getParameter("email");
final String subject = "Book Issued From Charusat Library.";
final String messg = total;
//response.sendRedirect("issuebook.jsp");
request.setAttribute("errorMessage1", "Book Issued Successfully");
RequestDispatcher dispatcher = request.getRequestDispatcher("issuebook.jsp");
dispatcher.forward( request, response);
// Sender's email ID and password needs to be mentioned
final String from = "[email protected]";
final String pass = "7383000598";
// Defining the gmail host
String host = "smtp.gmail.com";
// Creating Properties object
Properties props = new Properties();
// Defining properties
props.put("mail.smtp.host", host);
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.user", from);
props.put("mail.password", pass);
props.put("mail.port", "465");
// Authorized the Session object.
Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, pass);
}
});
try {
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(mailSession);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set Subject: header field
message.setSubject(subject);
// Now set the actual message
message.setText(messg);
// Send message
Transport.send(message);
// request.setAttribute("errorMessage1", "Book Issued Successfully");
// RequestDispatcher dispatcher = request.getRequestDispatcher("issuebook.jsp");
// dispatcher.forward( request, response);
// //response.sendRedirect("issuebook.jsp");
result = "Your mail sent successfully....";
//response.sendRedirect("issuebook.jsp");
}
catch (MessagingException mex) {
mex.printStackTrace();
result = "Error: unable to send mail....";
//response.sendRedirect("returnbook.jsp");
}
// catch (IllegalStateException e)
// {
// response.sendRedirect("returnbook.jsp");
// }
// catch(Exception e)
// {
// response.sendRedirect("issuebook.jsp");
// }
%>