묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
Jsp 에서 디비에다가 한글 값을 입력하고싶은데..
2002.08.04 20:59
<%@ page language = "java" import = "java.sql.*" contentType = "text/html;charset=euc-kr" %>
<html>
<head>
<style type="text/css">
<!--
td {font-family:tahoma; /*font-style: italic;*/
font-weight:700; font-size: 11pt; color:#9370DB;}
-->
</style>
</head>
<body>
<center>
<%
String k = new String(request.getParameter("korean").getBytes("8859_1"),"euc-kr");
Class.forName("org.gjt.mm.mysql.Driver");
Connection Conn = DriverManager.getConnection("jdbc:mysql://localhost/libsboard","admin","xxx");
PreparedStatement pstmt = Conn.prepareStatement
("insert into testk (test) values (?)");
pstmt.setString(1,k);
pstmt.executeUpdate();
pstmt.close();
Conn.close();
%>
<form>
<input type = "text" name = "korean">
</form>
</body>
</html>
이게 소스구요 ;; 에러가 자꾸 뜨네요 ;;
이런에러가 떠요
Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error
--------------------------------------------------------------------------------
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at org.apache.jsp.$121$jsp._jspService($121$jsp.java:60)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Unknown Source)
--------------------------------------------------------------------------------
소스 뭐가틀렸나요?
<html>
<head>
<style type="text/css">
<!--
td {font-family:tahoma; /*font-style: italic;*/
font-weight:700; font-size: 11pt; color:#9370DB;}
-->
</style>
</head>
<body>
<center>
<%
String k = new String(request.getParameter("korean").getBytes("8859_1"),"euc-kr");
Class.forName("org.gjt.mm.mysql.Driver");
Connection Conn = DriverManager.getConnection("jdbc:mysql://localhost/libsboard","admin","xxx");
PreparedStatement pstmt = Conn.prepareStatement
("insert into testk (test) values (?)");
pstmt.setString(1,k);
pstmt.executeUpdate();
pstmt.close();
Conn.close();
%>
<form>
<input type = "text" name = "korean">
</form>
</body>
</html>
이게 소스구요 ;; 에러가 자꾸 뜨네요 ;;
이런에러가 떠요
Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error
--------------------------------------------------------------------------------
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at org.apache.jsp.$121$jsp._jspService($121$jsp.java:60)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Unknown Source)
--------------------------------------------------------------------------------
소스 뭐가틀렸나요?
String k = new String(request.getParameter("korean").getBytes("8859_1"),"euc-kr");
문법상으로는 전혀 틀린데가 없습니다.
다만 request.getParameter("korean") 이 부분은 121.jsp?korean=xxx 이런 식으로 썼을때
xxx 라는 값을 취하라는 건데요... korean=xxx 이부분을 생략하고 그냥 호출하게 되면
request.getParameter("korean")는 null 이 됩니다.
즉 null 값을 getByte()해서 한글로 변환할 수 없기 때문에 생기는 오류네요.
파일을 호출할 때 121.jsp?korean=xxx 식으로 반드시 적어 주시거나
아님 예외처리를 하셔야겠네요. 이를테면 다음과 같이요...
<%
String temp = request.getParameter("korean");
if (temp != null) {
String k = new String(temp.getBytes("8859_1"),"euc-kr");
Class.forName("org.gjt.mm.mysql.Driver");
Connection Conn = DriverManager.getConnection("jdbc:mysql://localhost/libsboard","admin","xxx");
PreparedStatement pstmt = Conn.prepareStatement("insert into testk (test) values (?)");
pstmt.setString(1,k);
pstmt.executeUpdate();
pstmt.close();
Conn.close();
}
%>