게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
JSP 질문있습니다
게시물ID : programmer_6447짧은주소 복사하기
작성자 : 모두까기
추천 : 0
조회수 : 428회
댓글수 : 5개
등록시간 : 2014/11/09 22:27:46
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<HEAD>
<TITLE> 중고장터 </TITLE>
<SCRIPT language="JavaScript">
function Check()
{

if (Write.title.value.length < 1) {
 alert("글제목을 입력하세요.");
 Write.write_title.focus();
 return false;
        }
if (Write.contents.value.length < 1) {
 alert("글내용을 입력하세요.");
 Write.content.focus();
 return false;
        }
</SCRIPT>
</HEAD>
<BODY>
<center>
<font size='3'> <center> <b>게시판 글쓰기 </b></center>  </font>
</center>
<TABLE border='0' width='600' cellpadding='0' cellspacing='0'>
 <TR>
  <TD><hr size='1' noshade>
  </TD>
  </TR>
</TABLE>
<FORM Name='Write'  Action='/jspbook/project/market_insert.jsp' Method=post enctype='multipart/form-data'>
<TABLE border='0' width='600' cellpadding='1' cellspacing='1'>
 <TR>
        <TD colspan='2'>
        
           <hr size='1' noshade>
        </TD>
 </TR>
 <TR>
    <center>
  
  <TD width='100' bgcolor='cccccc'>
   <font size='2'><b>글 제목</b></font>
  </TD>
  
  <TD>
   <font size='2'><input type='text' size='70' maxlength='50' name='title'></font>
  </TD>
    </center>
 </TR>
 
 <TR>
  <TD bgcolor='cccccc'>
   <font size='2'><center><b>글 내용</b></center></font>
  </TD>
  <TD>
           <font size='2'>
           <textarea cols='70' rows='15' wrap='virtual' name='contents' ></textarea>
           </font>
        </TD>
 </TR>
 <TR>
        <TD colspan='2'>
           <hr size='1' noshade>
        </TD>
 </TR>
 
</TABLE>
<input type="file" name="filename1" size=40><br>
<input Type = 'Reset' Value = '다시 작성'>
<input Type ='Submit' Value = '등록'>
</FORM>
 

</BODY>
</HTML>

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@page import="java.util.regex.Pattern"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
<head>
<%@ page import="com.oreilly.servlet.MultipartRequest,com.oreilly.servlet.multipart.DefaultFileRenamePolicy,java.util.*,java.io.*" %>
<%
request.setCharacterEncoding("euc-kr");
 String realFolder = "";
 String filename1 = "";
 int maxSize = 1024*1024*5;
 String encType = "euc-kr";
 String savefile = "img";
 ServletContext scontext = getServletContext();
 realFolder = scontext.getRealPath(savefile);
 
 try{
  MultipartRequest multi=new MultipartRequest(request, realFolder, maxSize, encType, new DefaultFileRenamePolicy());
  Enumeration<?> files = multi.getFileNames();
     String file1 = (String)files.nextElement();
     filename1 = multi.getFilesystemName(file1);
 } catch(Exception e) {
  e.printStackTrace();
 }
 
 String fullpath = realFolder + "\\" + filename1;
%>
<title>Insert title here</title>
</head>
<body>
 <%!
 public String getTimeStampString()    //date type 맞추기
 {
     SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
     return formatter.format(new Date());
 }
%>
<%  int idx = 1;
String name =(String)session.getAttribute("logname"); 
String title = (String)request.getParameter("title");
String content = (String)request.getParameter("contents");
    if(title == "" ||title == null) out.println("title이 null입니다.");
   
    
    if(content == "" ||content == null) out.println("content가 null입니다.");
    
    String dburl="JDBC:MYSQL://LOCALHOST:3306/TEST";
    String dbuser="root";
    String dbpass="20113041";
    Connection conn =null;
    Statement pstmt = null;
    ResultSet rs =null;
    try{    //예외처리
        Class.forName("com.mysql.jdbc.Driver");
    }catch(ClassNotFoundException e){
        out.print("where is you mysql jdbc driver?");
        e.printStackTrace();
        return;
    }
    conn = DriverManager.getConnection(dburl, dbuser, dbpass);
    pstmt = conn.createStatement();
out.println(fullpath);
   
    String sql ="INSERT INTO market(market_TITLE,market_CONTENT,market_writeday,market_COUNT,market_writer,market_img)"+"VALUES('"+title+"','"+content+"','"+getTimeStampString()+"','"+idx+"','"+name+"','"+fullpath+"')";
     pstmt.executeUpdate(sql); 
     conn.close();
 
%>
</body>
</html>
 
굵게 표시된 부분이 데이터 전송인데요  왜 이미지 파일경로는 뜨는데 타이틀이랑 콘텐츠가 널값이 나올까요 ...?
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호