servlet 执行连接池代码提示500错误
具体代码(依赖是在pom.xml中插入的)
报的是DButil类找不到的错误,你仔细检查一下,我记得这个问题出现过两次了,你可以看看我之前写过的问答,代码和你一样都是类找不到的错误,看看我写的问答http://t.csdn.cn/bFyqM
target下面有没有DButil类,有没有.properties文件,有任何问题联系我
项目build构建一下,重新运行。
dao的代码发一下
pom里面的包都引入了吗
package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse res)
throws ServletException, IOException {
/*
* 1. 获取ServletContext对象
* 2. 从ServletContext对象中获取名为count的属性
* 3. 如果存在:给访问量加1,然后再保存回去;
* 4. 如果不存在:说明是第一次访问,向Servletcontext中保存名为count的属性,值为1
*/
ServletContext application = this.getServletContext();
Integer count = (Integer) application.getAttribute("count");
if (count == null) {
application.setAttribute("count", 1);
} else {
application.setAttribute("count", count+1);
}
res.setCharacterEncoding("utf-8");
res.setContentType("text/html;charset=utf-8");
/*
* 向浏览器输出
* 需要使用响应对象!
*/
System.out.println("本网站访问量:"+count+"人");
PrintWriter out = res.getWriter();
out.print("本网站访问量:" + count + "人");
out.flush();
out.close();
}
}
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Servlet03</display-name>
<servlet>
<servlet-name>AServlet</servlet-name>
<servlet-class>com.servlet.AServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AServlet</servlet-name>
<url-pattern>/AServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>