用jsp写好的registerForm.jsp注册页面跳转到register.jsp页面执行,出现以下错误
(另附上register.jsp代码)
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: An exception occurred processing JSP page /register.jsp at line 3229: String requsername=request.getParameter("username");//接收参数username
30: String reqpassword=request.getParameter("userpassword");//接收参数password
31: %>
32: <%
33: String url="jdbc:sqlserver://localhost:1433;DatabaseName=news"; //url地址,news是数据库名称
34: String users="rr";
35: String password="r1";
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause java.lang.NullPointerException
org.apache.jsp.register_jsp._jspService(register_jsp.java:111)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、register.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'register.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<%
request.setCharacterEncoding("gb2312");//设置接收编码格式
String requsername=request.getParameter("username");//接收参数username
String reqpassword=request.getParameter("userpassword");//接收参数password
%>
<%
String url="jdbc:sqlserver://localhost:1433;DatabaseName=news"; //url地址,news是数据库名称
String users="rr";
String password="r1";
Connection conn=null;
PreparedStatement pstmt=null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");//加载jdbc驱动程序
conn=java.sql.DriverManager.getConnection(url,users,password);//连接数据库
}
catch(ClassNotFoundException e)
{
out.println("找不到驱动类");//抛出异常,提示错误
}
catch(SQLException e){
out.println("连接数据库失败!");
}
try{
String adduser="insert into user values(null,?,?)";//增加一条用户信息
pstmt=conn.prepareStatement(adduser); //创建语句对象prepareStatement
pstmt.setString(1,requsername);//设置参数,接收到的用户名
pstmt.setString(2,reqpassword);//设置参数,接收到的密码
pstmt.executeUpdate();//添加注册用户
out.println("用户注册成功,请登录");
}
catch(SQLException e){
out.println("添加用户信息失败!");
}
//关闭数据库连接
try{if(pstmt!=null){
pstmt.close(); //关闭预处理语句对象
pstmt=null;
}
if(conn!=null){
conn.close();//关闭数据库连接
conn=null;
}
}catch(Exception e){
out.println("数据库关闭异常!");
}
%>
<jsp:forward page="login.jsp"></jsp:forward>
</body>
</html>
(另附上register.jsp代码)
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: An exception occurred processing JSP page /register.jsp at line 3229: String requsername=request.getParameter("username");//接收参数username
30: String reqpassword=request.getParameter("userpassword");//接收参数password
31: %>
32: <%
33: String url="jdbc:sqlserver://localhost:1433;DatabaseName=news"; //url地址,news是数据库名称
34: String users="rr";
35: String password="r1";
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause java.lang.NullPointerException
org.apache.jsp.register_jsp._jspService(register_jsp.java:111)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、register.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'register.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<%
request.setCharacterEncoding("gb2312");//设置接收编码格式
String requsername=request.getParameter("username");//接收参数username
String reqpassword=request.getParameter("userpassword");//接收参数password
%>
<%
String url="jdbc:sqlserver://localhost:1433;DatabaseName=news"; //url地址,news是数据库名称
String users="rr";
String password="r1";
Connection conn=null;
PreparedStatement pstmt=null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");//加载jdbc驱动程序
conn=java.sql.DriverManager.getConnection(url,users,password);//连接数据库
}
catch(ClassNotFoundException e)
{
out.println("找不到驱动类");//抛出异常,提示错误
}
catch(SQLException e){
out.println("连接数据库失败!");
}
try{
String adduser="insert into user values(null,?,?)";//增加一条用户信息
pstmt=conn.prepareStatement(adduser); //创建语句对象prepareStatement
pstmt.setString(1,requsername);//设置参数,接收到的用户名
pstmt.setString(2,reqpassword);//设置参数,接收到的密码
pstmt.executeUpdate();//添加注册用户
out.println("用户注册成功,请登录");
}
catch(SQLException e){
out.println("添加用户信息失败!");
}
//关闭数据库连接
try{if(pstmt!=null){
pstmt.close(); //关闭预处理语句对象
pstmt=null;
}
if(conn!=null){
conn.close();//关闭数据库连接
conn=null;
}
}catch(Exception e){
out.println("数据库关闭异常!");
}
%>
<jsp:forward page="login.jsp"></jsp:forward>
</body>
</html>
解决方案 »
- java.lang.ClassCastException: [Ljava.lang.Object;
- 兄弟们,给几个网页音乐播放器例子啊
- JSP自定义函数不能访问javabean么?【求助在线等】
- 如何禁止拖拽子窗口
- 网页中如何继承播放器?
- 为什么我的jsp跳转不正确?我已经设置好了web.xml
- Not binding factory to JNDI, no JNDI name configured
- 请各位大虾帮我看看这个处理blob的程序!
- 在bean中写了一个有3个参数的方法,那么在JSP中如何写setProperty?
- 使用web logic 的时候总是报这个错,求教大神帮解决ava.lang.OutOfMemoryError: PermGen space 在线等!!!
- java用webservice作接口有什么好处?直接提供一个请求地址就行了啊?
- 求MVC历史
29: String requsername=request.getParameter("username");//接收参数username
30: String reqpassword=request.getParameter("userpassword");//接收参数password
不需要.toString吗???
pstmt.setString(2,reqpassword);//设置参数,接收到的密码
这个看看有没有问题,看看requsername跟reqpassword是否有值,如果没值这里会报错!
如果是这个原因,你看看是不是你的不是用form提交过来的,你是否在jsp提交时忘记用form标签了。
if(request.getParameter("username")!=null)
{
String requsername=request.getParameter("username");//接收参数username
}
if(request.getParameter("userpassword")!=null)
{
String reqpassword=request.getParameter("userpassword");//接收参数password
}