回 帖 发 新 帖 刷新版面

主题:表单数据写入mysql

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ import="java.sql.*"%>
<!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=gb2312">
<title>会员信息</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<style type="text/css">
<!--
.style2 {color: #0000FF}
-->
</style>
</head>

<body>
<div id="Layer1" style="position:absolute; left:196px; top:84px; width:619px; height:312px; z-index:1; background-color: #CCDCF4; border: 1px none #000000;">
  <p>
  <%   request.setCharacterEncoding("gb2312");   %> 
    <%
int i=0;
String hname=null;
hname=request.getParameter("name");
if(hname==null)
hname="";
byte b[]=hname.getBytes("ISO-8859-1");
hname=new String(b);
%>
</p>
  <p>    
<%
String hpassword1=request.getParameter("password1");
double str1=0;
if(hpassword1!=null)
 str1=Double.parseDouble(hpassword1);
String hpassword2=request.getParameter("password2");
double str2=0;
if(hpassword2!=null)
 str2=Double.parseDouble(hpassword2);
 String str=request.getParameter("email");
%>
<%
String connectionURL="jdbc:mysql://localhost:3306/membership?"+"user=root&password=200537";
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(connectionURL);
Statement stmt=con.createStatement();
con.setAutoCommit(false);
updateResult=stmt.executeUpdate("insert into member(mname,mpassword1,mpassword2,memail) values('"+hname+",'"+str1+"','"+str2+"','"+str+"');");
con.commit();
%>
<script>
alert("注册成功,请登录");
</script>
<% 
}
catch(SQLException e)
{
%>
<script>
alert("注册失败,请重试!");
</script>
<% 
con.rollback();
}
finally{con.close();}
%>

  <span class="style2"></p>
  <p>
  </p>
</div>

</body>
</html>
错误提示:org.apache.jasper.JasperException: /xianshi.jsp(2,4) Invalid directive
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:90)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:506)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1539)
    org.apache.jasper.compiler.Parser.parse(Parser.java:126)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

回复列表 (共1个回复)

沙发

<%@ import="java.sql.*"%>改成
<%@ page import="java.sql.*"%>

我来回复

您尚未登录,请登录后再回复。点此登录或注册