问题描述
<%@ page language="java" import="java.sql.*"%><%@ page contentType="text/html;charset=GB18030"%><%@ page import="java.util.*" %><%reponse.setCharacterEncoding("GB18030");String susername,spassward,school,scho,sclass,stel,sgender;susername=request.getParameter("Name");spassword=request.getParameter("passward1");school=request.getParameter("xueyuan");scho=request.getParameter("zhuanye");sclass=request.getParameter("nianji");stel=request.getParameter("number");sgender=request.getParameter("gender");String insertquery= "insert into student set Name='"+susername+"',passward1='"+spassward+"',xueyuan='"+school+"',number='"+stel+"',zhuanye='"+scho+"',nianji='"+sclass+"',number='"+stel+"',gender='"+sgender+"'";String selectquery="select * from student where Name='"+susername+";Connction conn=null;Statement stmt=null;Resultset rs=null;try{Class.forName("com.mysql.jdbc.Driver").newInstance();conn= DriverManager.getConnection("jdbc:mysql://localhost/test","root","root");stmt= conn.createStatement();rs=stmt.executeQuery(selectquery);if(rs.next()){response.sendRendirect("register.jsp");}return;}else{stmt.executeQuery(insertquery);}}catch(SQLException ex){ex.printStackTrace();response.sendRendirect("login.jsp");}finally{stmt.close();conn.close();} %> 问题补充:deny_guoshou 写道
解决方案
1、你输出一下要插入的信息,看看有没有为null的数据或者是乱码。2、你要补充一下异常的信息是什么,比如这样子:type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372) 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) root cause java.lang.NullPointerException org.apache.jsp.submit_jsp._jspService(submit_jsp.java:107) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) 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) 有这些才好找错误。。。
解决方案二:
能不能详细点,给出所有的异常报告。就这点信息,大家很难找到解决方案的。