-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanswer.jsp
71 lines (58 loc) · 1.85 KB
/
answer.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
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Q&A</title>
</head>
<body style="background-color:#F0F8FF;">
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://group31.cwwhhyxvfxql.us-east-2.rds.amazonaws.com:3306/group31","Yuchen_jin","Jinyuchen2016*");
Statement st = con.createStatement();
String str = "select * from Question";
ResultSet rs=st.executeQuery(str);
while(rs.next()){
int id = rs.getInt("qid");
out.print("Question: " + rs.getString("question")+"<br/>" +"<br/>");
String ans = rs.getString("answer");
if(ans != null && !ans.isEmpty()){
out.print("Answer: " + ans);
out.print("<br/>" + "<br/>");
}
//else{
%>
<form action="post_ans.jsp" method="post">
<input type = "hidden" name = "qid" value = "<%=id%>">
<table>
<tr>
<td>Edit Answer:</td>
<td><input type="text" name="ans" value=""/></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
<br><br><hr>
<%
//while(ans == null && ans.isEmpty()){}
//ans = request.getParameter("ans");
//if(ans != null && !ans.isEmpty()){
//out.print("Answer: " + ans+"<br/>");}
//String update = "UPDATE Question SET answer = ? WHERE id = ?";
//}
}
con.close();
}catch (Exception ex) {
out.print("Error occured");
}
%>
</body>
</html>