묻고답하기
어느부분 오류인지 모르겠습니다..
2017.06.19 12:58
insertForm.jsp 파일에서 실행 후 추가 하면 insertPro.jsp 파일로 action을 통해 가진다음에
insertPro.jsp파일에서 response.sendRedirect("list.jsp?id="+id); 을 통해 list.jsp로 가지게 되어있는 구조인데 무엇때문인지 자꾸 insertForm에서 추가를 하면 문제가 추가되지 않았다고만 뜹니다... 꼭 좀 부탁드려요!
insertForm.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<link rel="stylesheet" href="style.css"/>
<form name="input" method="post" action="insertPro.jsp">
<table width=600 border=1 bordercolor="black">
<tr>
<td class="label"><label for="question">문제</label>
<td class="content"><input id="question" name="question" type="text" size="100"
maxlength="50" autofocus required></td></tr>
<tr>
<td align='center'>보기</td><td align='center'>내용</td></tr>
<tr>
<td class="label"><label for="ex1">1</label>
<td class="content"><input id="ex1" name="ex1" type="text"
size="100" maxlength="50" required></td></tr>
<tr>
<td class="label"><label for="ex2">2</label>
<td class="content"><input id="ex2" name="ex2" type="text"
size="100" maxlength="50" required></td></tr>
<tr>
<td class="label"><label for="ex3">3</label>
<td class="content"><input id="ex3" name="ex3" type="text"
size="100" maxlength="50" required></td></tr>
<tr>
<td class="label"><label for="ex4">4</label>
<td class="content"><input id="ex4" name="ex4" type="text"
size="100" maxlength="50" required></td></tr>
<tr>
<td class="label"><label for="dap">정답</label>
<td class="content"><input id="dap" name="dap" type="text"
size="100" maxlength="50" required></td></tr>
<tr>
<td align='center' class="label2" colspan="2"><input type="submit" value="출제하기">
<input type="reset" value="다시작성"></td></tr>
</table>
</form>
insertPro.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<% request.setCharacterEncoding("utf-8");%>
<%
String id = request.getParameter("id");
String question= request.getParameter("question");
String ex1 = request.getParameter("ex1");
String ex2 = request.getParameter("ex2");
String ex3 = request.getParameter("ex3");
String ex4 = request.getParameter("ex4");
String dap = request.getParameter("dap");
Timestamp reg_date=new Timestamp(System.currentTimeMillis());
Connection conn=null;
PreparedStatement pstmt=null;
String str="";
try{
String jdbcUrl="jdbc:mysql://localhost:3306/jsptest?useUnicode=true&characterEncoding=UTF-8";
String dbId="jspid";
String dbPass="jsppass";
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(jdbcUrl,dbId ,dbPass);
String sql= "insert into member values (?,?,?,?,?,?,?,?)";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,id);
pstmt.setString(2,question);
pstmt.setString(3,ex1);
pstmt.setString(4,ex2);
pstmt.setString(5,ex3);
pstmt.setString(6,ex4);
pstmt.setString(7,dap);
pstmt.setTimestamp(8,reg_date);
pstmt.executeUpdate();
response.sendRedirect("list.jsp?id="+id);
}catch(Exception e){
e.printStackTrace();
out.println("문제가 제대로 출제되지 않았습니다.");
}finally{
if(pstmt != null)
try{pstmt.close();}catch(SQLException sqle){}
if(conn != null)
try{conn.close();}catch(SQLException sqle){}
}
%>
list.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<link rel="stylesheet" href="style.css"/>
<td><a href="insertForm.jsp?id">퀴즈출제</a></td>
<table border=1 cellspacing=0 cellpadding=4>
<tr class="label">
<td>번호</td>
<td>제목</td>
<td>출제일시</td>
<td>삭제</td>
</tr>
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
try{
String jdbcUrl="jdbc:mysql://localhost:3306/jsptest?useUnicode=true&characterEncoding=UTF-8";
String dbId="jspid";
String dbPass="jsppass";
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(jdbcUrl,dbId ,dbPass );
String sql= "select * from id";
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next()){
String id= rs.getString("id");
String question= rs.getString("question");
Timestamp reg_date=rs.getTimestamp("reg_date");
%>
<tr>
<td><%=id%></td>
<td><%=question%></td>
<td><%=reg_date.toString()%></td>
<td><a href="deletePro.jsp?id=<%=id%>">삭제</a></td>
</tr>
<% }
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs != null)
try{rs.close();}catch(SQLException sqle){}
if(pstmt != null)
try{pstmt.close();}catch(SQLException sqle){}
if(conn != null)
try{conn.close();}catch(SQLException sqle){}
}
%>
</table>
여긴 jsp를 전문으로 하는 작업자들이 별로 없을겁니다.