求解:Tomcat实例化Servlet类异常?

求解:运行web项目时报错实例化servlet类异常
初学者,接触不到一年。
jdk使用的是jdk13,按照老师要求并未使用集成开发环境,使用的是记事本进行编写,javaBean和Servlet可以正常编译产生class文件
环境变量已经配置完成,tomcat使用的是9.0.37
包也已经创建好
javabean包 WEB-INF>classes>mybean>data>
javaservlet包 WEB-INF>classes>muservlet>control>
本意是制作一个期末作业,一个注册界面,数据库已经创建完成,运行时发生以下错误
错误

jsp界面,可以正常显示
inputRegisterMess.jsp

<%@ page contentType="text/html;charset=GB2312" %>
<jsp:useBean id="userBean" class="mybean.data.Register" scope="request"></jsp:useBean>
<head>
<%@ include file="head.txt" %>
</head>
	<title>注册成为国家公民</title>
<html>
<body background=image>
	<font face="黑体" size=2>
	<div align="center">
	<form action="registerServlet" method="post" name=form>
	<table>
		用户名由字母,数字,下划线构成,*注释的项必须填写。
		<tr><td>*公民名称:</td><td><Input type=text name="logname"></td></tr>
		<tr><td>*用户密码:</td><td><Input type=text name="password"></td></tr>
		<tr><td>*确认密码:</td><td><Input type=password name="again_password"></td></tr>
		<tr><td>联系电话:</td><td><Input type=text name="phone"></td></tr>
		<tr><td>常用地址:</td><td><Input type=text name="address"></td></tr>
		<tr><td>真实姓名:</td><td><Input type=text name="realname"></td></tr>
		<tr><td><Input type=submit name="g" value="提交"></td></tr>
	</table>
	</form>
	</div>
	<div align="center">
	<p>公民执照:
	<jsp:getProperty name="userBean" property="backNews"/>
	<table border=3>
		<tr><td>公民名称:</td>
		<td><jsp:getProperty name="userBean" property="logname"/></td>
		</tr>
		<tr><td>真实姓名:</td>
		<td><jsp:getProperty name="userBean" property="realname"/></td>
		</tr>
		<tr><td>常用地址:</td>
		<td><jsp:getProperty name="userBean" property="address"/></td>
		</tr>
		<tr><td>联系电话:</td>
		<td><jsp:getProperty name="userBean" property="phone"/></td>
		</tr>
		</table>
		</div>
</body>
</html>

web.xml配置文件

<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app>
<servlet>
	<servlet-name>registerServlet</servlet-name>
	<servlet-class>myservlet.control.HandleRegister</servlet-class>
</servlet>
<servlet-mapping>
	<servlet-name>registerServlet</servlet-name>
	<url-pattern>/registerServlet</url-pattern>
</servlet-mapping>
<servlet>
	<servlet-name>loginServlet</servlet-name>
	<servlet-class>myservlet.control.HandleLogin</servlet-class>
</servlet>
<servlet-mapping>
	<servlet-name>loginServlet</servlet-name>
	<url-pattern>/loginServlet</url-pattern>
</servlet-mapping>
</web-app>

javaBean文件
Register.java(可正常编译)

package mybean.data;
public class Register{
	String logname="",phone="",address="",realname="",backNews="请输入信息";
	public void setLogname(String logname){
		this.logname=logname;
	}
	public String getLogname(){
		return logname;
	}
	public void setPhone(String phone){
		this.phone=phone;
	}
	public String getPhone(){
		return phone;
	}
	public void setAddress(String address){
		this.address=address;
	}
	public String getAddress(){
		return address;
	}
	public void setRealname(String realname){
		this.realname=realname;
	}
	public String getRealname(){
		return realname;
	}
	public void setBackNews(String backNews){
		this.backNews=backNews;
	}
	public String getBackNews(){
		return backNews;
	}
}

javaServlet文件
HandleRegister.java(可正常编译)

package myservlet.control;
import mybean.data.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HandleRegister extends HttpServlet{
	public void init(ServletConfig config) throws ServletException{
		super.init(config);
		try{
			Class.forName("com.sqlserver.jdbc.Driver");
		}
		catch(Exception e){}
	}
	public String handleString(String s){
		try{
			byte bb[ ]=s.getBytes("iso-8859-1");
			s=new String(bb);
		}
		catch(Exception ee){}
		return s;
	}
	public void doPost(HttpServletRequest request,HttpServletResponse
		response)throws ServletException,IOException{
		String uri="jdbc:sqlserver://127.0.0.1/shop?"+"person=sa&123=& characterEncoding=gb2312";
		Connection con;
		PreparedStatement sql;
		Register userBean=new Register();
		request.setAttribute("userBean",userBean);
		String logname=request.getParameter("logname").trim();
		String password=request.getParameter("password").trim();
		String again_password=request.getParameter("again_password").trim();
		String phone=request.getParameter("phone").trim();
		String address=request.getParameter("address").trim();
		String realname=request.getParameter("realname").trim();
		if(logname==null)
			logname="";
		if(password==null)
			password="";
		if(!password.equals(again_password)){
			userBean.setBackNews("请这位先生输入两次相同的密码!");
			RequestDispatcher dispatcher=
			request.getRequestDispatcher("inputRegisterMess.jsp");
			dispatcher.forward(request,response);
			return;
		}
		boolean isLD=true;
		for(int i=0;i<logname.length();i++){
			char c=logname.charAt(i);
				if(!((c<='z'&&c>='a')||(c<='Z'&&c>='A')||(c<='9'&&c>='0')))
					isLD=false;
		}
		boolean boo=logname.length()>0&&password.length()>0&&isLD;
		String backNews="";
		try{
			con=DriverManager.getConnection(uri);
			String insertCondition="INSERT INTO user VALUES (?,?,?,?,?)";
			sql=con.prepareStatement(insertCondition);
			if(boo){
				sql.setString(1,handleString(logname));
				sql.setString(2,handleString(password));
				sql.setString(3,handleString(phone));
				sql.setString(4,handleString(address));
				sql.setString(5,handleString(realname));
				int m=sql.executeUpdate();
				if(m!=0){
					backNews="恭喜你成为“玩家国度”新的公民!";
					userBean.setBackNews(backNews);
					userBean.setLogname(logname);
					userBean.setPhone(handleString(phone));
					userBean.setAddress(handleString(address));
					userBean.setRealname(handleString(realname));
				}
			}
			else{
				backNews="信息不全或存在违规字符,请重新填写";
				userBean.setBackNews(backNews);
			}
			con.close();
		}
		catch(SQLException exp){
			backNews="该用户名已被占用,请重新填写"+exp;
			userBean.setBackNews(backNews);
		}
		RequestDispatcher dispatcher=
		request.getRequestDispatcher("inputRegisterMess.jsp");
		dispatcher.forward(request,response);
	}
	public void doGet(HttpServletRequest request,HttpServletResponse
		response)throws ServletException,IOException{
	doPost(request,response);
	}
}

感谢各位带佬路过相助,我真的解决不了了!!!

  • 3
    点赞
  • 11
    评论
  • 2
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

评论 11 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:游动-白 设计师:我叫白小胖 返回首页

打赏作者

小小阿狸233

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值