[jsp]jsp 질문드립니다.
글쓴이: lalupo20 / 작성시간: 금, 2019/04/26 - 6:01오후
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="java.sql.*" %> <%@ page import="java.sql.Connection" %> <%@ page import="java.sql.DriverManager" %> <%@ page import="com.keehl.DataContainer" %> <%@ page import="com.keehl.BoardManager" %> <script language="javascript"> function loginCheck() { var form = document.loginform; if (!form.userId.value) { alert("아이디를 적어주세요."); form.userId.focus(); return; } if (!form.userPassword.value) { alert("비밀번호를 적어주세요."); form.userPassword.focus(); return; } form.submit(); } </script> <!DOCTYPE html> <html> <head> <title>게시판</title> <style> .mainContainer { background:white; width:100%; height:100%; } ul { list-style:none; margin:0; padding:0; } li { margin: 5px 5px 5px 5px; padding: 5px 5px 5px 5px; border : 0; float:left; display:inline-block; } .buttonContainer { background:skyblue; text-align:center; height: 70px; } .tab { background:skyblue; border:1px solid skyblue; border-radius:10%; text-align:center; font-size: 40px } .loginForm { display:inline-block; background:lightgray; width:15%; height:30%; } .homeImage { display:inline-block; position:absolute; width: 100%; height: 100%; } .boardForm { display:inline-block; position:absolute; width: 100%; height: 100%; } .mainForm { display:inline-block; position:absolute; width: 100%; height: 100%; } #topBar{ background:rgba(200, 200, 255, 1.0); text-align:center; } </style> </head> <body> <script> document.oncontextmenu = function (e) { alert("오른쪽버튼을 이용할 수 없습니다."); return false; } </script> <div class="mainContainer"> <h1><a href="../main.jsp" style="text-decoration:none">DAESUNG</a></h1> <div class="buttonContainer"> <ul> <li> <a class="menuLink" href="../information/introduceAcademy.jsp" style="text-decoration:none"><div class="tab">학원소개</div></a> </li> <li> <a class="menuLink" href="../information/introduceSubjects.jsp" style="text-decoration:none"><div class="tab">강좌소개</div></a> </li> <li> <a class="menuLink" href="../board/boardList.jsp" style="text-decoration:none"><div class="tab">자유게시판</div></a> </li> <li> <a class="menuLink" href="../faq/boardList.jsp" style="text-decoration:none"><div class="tab">FAQ</div></a> </li> <li> <a class="menuLink" href="../qa/boardList.jsp" style="text-decoration:none"><div class="tab">질문과 답변</div></a> </li> <li> <a class="menuLink" href="../media/boardList.jsp" style="text-decoration:none"><div class="tab">샘플강좌</div></a> </li> <li> <a class="menuLink" href="../video/boardList.jsp" style="text-decoration:none"><div class="tab">강의실</div></a> </li> <li> <a class="menuLink" href="../information/wayToCome.jsp" style="text-decoration:none"><div class="tab">오시는길</div></a> </li> </ul> </div> <% int total = 0; Connection con = null; try{ String url = "jdbc:mysql://localhost:3306/-"; String id = "-"; String pw = "-"; Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection(url, id, pw); Statement stat = con.createStatement(); String sqlCount = "SELECT COUNT(*) FROM video"; String temp = request.getParameter("subjectSelect"); int subjectNum = 0; if (temp == null) { subjectNum = 1; } else { subjectNum = Integer.parseInt(request.getParameter("subjectSelect")); } out.println(subjectNum); ResultSet rs = stat.executeQuery(sqlCount); if (rs.next()) { total = rs.getInt(1); } rs.close(); %> <% //out.print("총 게시물 : " + total + "개"); String sqlList = "SELECT num, subject, userName, title, time, hit from video;"; rs = stat.executeQuery(sqlList); %> <form name=loginform method=post action="../login_ok.jsp"> <form name=joinform method=post action="../join_ok.jsp"> <% if (DataContainer.getCookies() == null) { %> <div class="loginForm"> <table border="0" width="240"> <tr height="40"> <td>아이디<input name="userId" type="text"></td> </tr> <tr height="40"> <td>비밀번호<input name="userPassword" type="password"></td> </tr> <tr height="40"> <td><input type=button name="login" value="로그인" OnClick="javascript:loginCheck();"></td> </tr> <tr height="40"> <td><input type=checkBox name="auto-login">자동로그인</td> </tr> <tr height="40"> <td><a OnClick="window.location='../joinForm.jsp'" style="text-decoration:none">회원가입</a>/<a href="http://www.google.com" style="text-decoration:none" >아이디, 비밀번호 찾기</a></td> </tr> </table> </div> <div class="mainForm"> <h2>로그인한 사용자만 이용 가능 합니다.</h2> </div> <% } else { %> <div class="loginForm"> <table border="0" width="240"> <tr height="40"> <td>아이디 : <%=DataContainer.getUserId() %></td> </tr> <tr height="40"> <td><a href="http://www.laromacorea.com">내 강의실</a></td> </tr> <tr height="40"> <td><a href="http://www.daum.net">마이페이지</a></td> </tr> <tr height="40"> <td><a href="../logout_ok.jsp">로그아웃</a></td> </tr> </table> </div> <div class="mainForm"> <table> <select name="subjectSelect"> <option value="0">과목 선택</option> <option value="1">건축기사필기</option> <option value="2">건축기사실기</option> </select> </tr> <tr height="5"> <td width="73"><div id="topBar">번호</div></td> <td width="200"><div id="topBar">과목</div></td> <td width="379"><div id="topBar">제목</div></td> <td width="73"><div id="topBar">작성자</div></td> <td width="164"><div id="topBar">작성일</div></td> <td width="58"><div id="topBar">조회수</div></td> <td width="7"></td> </tr> <% if (total == 0) { %> <tr align="center" bgcolor="#FFFFFF" height="30"> <td colspan="6"> 등록된 글이 없습니다.</td></tr> <% } else { while (rs.next()); while(rs.previous()) { int idx = rs.getInt(1); int sub = rs.getInt(2); if (sub != subjectNum) continue; String name = rs.getString(3); String title = rs.getString(4); String time = rs.getString(5); int hit = rs.getInt(6); %> <tr height="25" align="center"> <td><%=idx %></td> <td align="center"><%=BoardManager.getSubjectTitle(sub) %></td> <td align="left"><a href="view.jsp?idx=<%=idx%>"><%=title %></a></td> <td align="center"><%=name %></td> <td align="center"><%=time %></td> <td align="center"><%=hit %></td> <td> </td> </tr> <tr height="1" bgcolor="#D2D2D2"><td colspan="6"></td></tr> <% } } %> </table> <table> <tr><td colspan="4" height="5"></td></tr> <tr align="center"> <td><input type=button value="글쓰기" OnClick="window.location='writePost.jsp'"></td> </tr> </table> </div> <% } } catch(SQLException e) { out.println(e.toString()); } %> </div> </body> </html>
위와 같은 코드에서
select 항목에서 선택한 목록에 따라
게시판에 출력되는 글들을 변경해주고 싶은데
어떻게 해야 하나요?
페이지 이동 없이
셀렉트한 값을 자바상에서 받아와서 다루는 방법이 있나요?
request.getParameter("subjectSelect")는 널값이 리턴됩니다.
jsp 기초가 없으니까 간단한 구현하는것도 힘드네요.
Forums:
댓글 달기