servlet中的空指针异常问题

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=utf-8");
String registername = "";
String registeremail = "";
String registerpassword = "";
List params = new ArrayList();
boolean flag = false;

    DataOutputStream output=new DataOutputStream(response.getOutputStream());   
    registername = request.getParameter("registername");
    registeremail = request.getParameter("registeremail");
    registerpassword = request.getParameter("registerpassword");

// System.out.println(registername);
// System.out.println(registeremail);
// System.out.println(registerpassword);
params.add(registername);
params.add(registeremail);
params.add(registerpassword);

    try {   
        flag = service.register(params);
        if(flag){
            output.writeUTF("SUCCESS");
        }else{
            output.writeUTF("FAIL");
        }
    }catch(Exception e){
        e.printStackTrace();
    }finally{
        output.flush();
        output.close();
    }       
}

这段代码一直在flag = service.register(params); 这行报告空指针异常,求解??
service的定义private RegisterService service= new RegisterDao();
RegisterService是接口,register方法的定义

public boolean register(List params) {
// TODO Auto-generated method stub
boolean flag = false;
String sql ="insert into userinfo(username,email,password) values(?,?,?)";
try {
jdbcUtil.getConnection();
flag = jdbcUtil.updateByPreparedStatement(sql, params);

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }finally{
        jdbcUtil.releaseConn();
    }
    return flag;
}

1个回答

debug 调试一下

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
本人初学者,写了一个servlet报空指针异常,求大神帮忙

java.lang.NullPointerException at com.nwnu.loginServlet.LoginServlet.doGet(LoginServlet.java:29) at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

servlet里写的转发语句报空指针异常

这句话request.getRequestDispatcher("/WEB-INF/picMng/listPic.jsp") .forward(request, response);报错。 准确的是 .forward(request, response)报错,求大神。谢谢

空指针异常,jsp+servlet+jdbc

login.jsp: ``` <form name="formName" method="post" action="servlet/AdminVerify"> <tr> <td width="18%" height="30"> <div align="center">用户</div> </td> <td width="50%" height="30"><input name="name" type="text"></td> <!-- 宽度规定,然后rowspan,则该列都合并,其他的行少出现一个td的使用 --> <td width="32%" rowspan="4"> <!-- input里面可以有斜杠,也可无 --> <!-- 注意"image"类型的用法,必须有图片src参数。它相当于一个按钮, 所以可以有onClick,且注意return及分号不能少,实际上传递的false值无意义--> <input type="image" name="imageField" src="images/dl.gif" onClick="return check();"> </td> </tr> <tr> <td height="30"> <div align="center">密码</div> </td> <td height="30"><input name="password" type="password"></td> </tr> <tr> <td height="30"> <div align="center">权限</div> </td> <td height="30"> <!-- 下拉列表,文本内容会显示 --> <select name="st"> <option value="管理员">管理员</option> <option value="客户">客户</option> </select> </td> </tr> <!-- table中的空白行和列可以有center,left,right属性的作用 --> <tr> <!-- 虽未空白行,但是td不能省略 --> <td height="30"></td> <td height="30"></td> </tr> </form> ``` web.xml: ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>hotel2</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>AdminVerify</servlet-name> <servlet-class>servlet.AdminVerify</servlet-class> </servlet> <servlet-mapping> <servlet-name>AdminVerify</servlet-name> <url-pattern>/servlet/AdminVerify</url-pattern> </servlet-mapping> </web-app> ``` AdminVerify.java: ``` package servlet; import java.io.*; import java.sql.*; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import service.Service; public class AdminVerify extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out=response.getWriter(); String name = request.getParameter("name"); String password = request.getParameter("password"); String st = request.getParameter("st"); Service service=new Service(); ResultSet rs=service.getResult(name,password,st); try {//rs出现的地方都需要try-catch if (!rs.next()) { out.print("<script>alert('你输入的用户不存在或密码错误,请重新登录!');window.history.go(-1);</script>"); } else { // // request.getSession().setAttribute("name", request.getParameter("name")); if (request.getParameter("st").equals("客户")) { //st一样赋值给session request.getSession().setAttribute("st", "客户"); } else { //password这里不必要放入session request.getSession().setAttribute("st", rs.getString("user_type")); } response.sendRedirect(request.getContextPath()+"/main.jsp"); } } catch (SQLException e) { e.printStackTrace(); } } } ``` Service.java: ``` package service; import java.sql.*; import java.util.*; import db.DBUtil; public class Service { private Connection conn; private Statement stmt; private ResultSet rs; private String sql; public ResultSet getResult(String name, String password, String st) { //这一句放到方法外面出现错误 conn=DBUtil.getConnection(); if (st.equals("客户")) { sql = "select * from customr where customer_name=name and customer_password=password"; } else { sql = "select * from users where user_name=name and user_password=password"; } try { // jsp没try不会报错,容易错误 stmt = conn.createStatement(); rs = stmt.executeQuery(sql); } catch (Exception e) { e.printStackTrace(); } // return rs; } } ``` java.lang.NullPointerException at servlet.AdminVerify.doPost(AdminVerify.java:30) 在if(!rs,next())处 com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'name' in 'where clause'

在servlet的doGet()里面调用方法一直报空指针异常

总共就一个超链接连了一个servlet servlet里的代码是: package com.simple.mvc; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/getAllProject") public class GetAllProjectServlet extends HttpServlet { private static final long serialVersionUID = 2L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DAO dao=new DAO(); List<Project> prs=dao.getAllProject(); System.out.println(prs.size()); } } DAO里面的代码是: package com.simple.mvc; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; import org.junit.Test; public class DAO { @Test public void test(){ DAO dao=new DAO(); List<Project> prs=dao.getAllProject(); System.out.println(prs.size()); } public List<Project> getAllProject(){ List<Project> prs=new ArrayList<>(); Connection connection =null; PreparedStatement preparedStatement=null; ResultSet resultSet=null; try { connection=JDBCTools.getConnection(); String sql="SELECT p_id,p_name,t_name "+ "FROM project p,teacher t "+ "WHERE p.`t_id`=t.`t_id` AND p_if=2"; preparedStatement = connection.prepareStatement(sql); resultSet = preparedStatement.executeQuery(); while(resultSet.next()){ int p_id=resultSet.getInt(1); String p_name=resultSet.getString(2); String t_name=resultSet.getString(3); Project project = new Project(p_id, p_name,t_name); prs.add(project); } } catch (Exception e) { e.printStackTrace(); }finally{ JDBCTools.release(resultSet, preparedStatement, connection); } return prs; } } 在超链接访问servlet时就报java.lang.NullPointerException 我看了是因为List<Project> prs=dao.getAllProject();返回为null 但是为什么会返回为null 我在DAO写了一个测试单元,测试返回不为null呀,求大神解答 报错内容为 java.lang.NullPointerException at java.util.Properties$LineReader.readLine(Properties.java:434) at java.util.Properties.load0(Properties.java:353) at java.util.Properties.load(Properties.java:341) at com.simple.mvc.JDBCTools.getConnection(JDBCTools.java:44) at com.simple.mvc.DAO.getAllProject(DAO.java:28) at com.simple.mvc.GetAllProjectServlet.doGet(GetAllProjectServlet.java:22) at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)0 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

空指针异常问题,怎么修改?

public ResultSet executeQuery(String sql) { try { // 捕捉异常 conn = getConnection(); // 调用getConnection()方法构造connection对象的一个实例conn stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(sql); } catch (SQLException ex) { System.err.println(ex.getMessage()); // 输出异常消息 } return rs; // 返回结果集对象 } 报错: java.lang.NullPointerException com.wgh.tools.ConnDB.executeQuery(ConnDB.java:56) com.wgh.dao.DiaryDao.queryDiary(DiaryDao.java:28) com.wgh.servlet.DiaryServlet.listAllDiary(DiaryServlet.java:249) com.wgh.servlet.DiaryServlet.doPost(DiaryServlet.java:52) com.wgh.servlet.DiaryServlet.doGet(DiaryServlet.java:66) javax.servlet.http.HttpServlet.service(HttpServlet.java:624) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) com.wgh.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:24) 下面这是56行: stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

java 传参失败 空指针异常

我在servlet里调用dao层方法 自定义了一个name变量做测试 name在整个servlet可以输出 但在dao层无法输出 ![这是servlet](https://img-ask.csdn.net/upload/201512/26/1451121687_607130.png) ![这是dao层和报的异常](https://img-ask.csdn.net/upload/201512/26/1451121729_387108.png)

关于servlet实现下载,点击取消时报空指针异常

如题,在我多次点击标题下载,取消之后,java后台就报空指针异常,而且点击下载标题也点击不了了,该怎么解决。 应该是点击取消的时候,客户端和服务端通过socket也建立了链接吧。 ![图片说明](https://img-ask.csdn.net/upload/201612/15/1481779156_396227.png) 重复1,2操作。 java.io.IOException: null at org.apache.coyote.http11.InternalAprOutputBuffer.flushBuffer(InternalAprOutputBuffer.java:205) ~[tomcat-coyote.jar:7.0.69] at org.apache.coyote.http11.InternalAprOutputBuffer.access$100(InternalAprOutputBuffer.java:37) ~[tomcat-coyote.jar:7.0.69] at org.apache.coyote.http11.InternalAprOutputBuffer$SocketOutputBuffer.doWrite(InternalAprOutputBuffer.java:235) ~[tomcat-coyote.jar:7.0.69] at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:119) ~[tomcat-coyote.jar:7.0.69] at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:192) ~[tomcat-coyote.jar:7.0.69] at org.apache.coyote.Response.doWrite(Response.java:499) ~[tomcat-coyote.jar:7.0.69] at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:402) ~[catalina.jar:7.0.69] at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480) ~[tomcat-coyote.jar:7.0.69] at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:310) ~[tomcat-coyote.jar:7.0.69] at org.apache.catalina.connector.OutputBuffer.writeByte(OutputBuffer.java:451) ~[catalina.jar:7.0.69] at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:77) ~[catalina.jar:7.0.69] at com.thunisoft.gpip.modules.procuratorial.util.DownloadServlet.doGet(DownloadServlet.java:62) ~[classes/:na] at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) ~[servlet-api.jar:na] at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) ~[servlet-api.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) [catalina.jar:7.0.69] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.69] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat7-websocket.jar:7.0.69] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.69] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.69] at com.thunisoft.summer.security.access.filter.ACFilter.doFilter(ACFilter.java:50) ~[summer-core-2.1.5.6.jar:2.1.5.6] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.69] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.69] at com.thunisoft.artery.support.filter.ThreadFilter.doFilter(ThreadFilter.java:56) [artery-platform-4.4.23.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.69] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.69] at com.thunisoft.summer.web.filter.ParameterFilter.doFilterInternal(ParameterFilter.java:72) [summer-core-2.1.5.6.jar:2.1.5.6] at com.thunisoft.summer.web.multipart.RequestWrapperFilter.doFilter(RequestWrapperFilter.java:138) [summer-core-2.1.5.6.jar:2.1.5.6] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.69] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.69] at com.thunisoft.summer.web.filter.CharsetFilter.doFilter(CharsetFilter.java:44) [summer-core-2.1.5.6.jar:2.1.5.6] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.69] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.69] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) [catalina.jar:7.0.69] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) [catalina.jar:7.0.69] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) [catalina.jar:7.0.69] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) [catalina.jar:7.0.69] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:7.0.69] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) [catalina.jar:7.0.69] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) [catalina.jar:7.0.69] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) [catalina.jar:7.0.69] at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) [tomcat-coyote.jar:7.0.69] at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) [tomcat-coyote.jar:7.0.69] at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517) [tomcat-coyote.jar:7.0.69] at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506) [tomcat-coyote.jar:7.0.69] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_80] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_80] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-coyote.jar:7.0.69] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]

tomcat 500 空指针异常

初学javaweb,写了一个非常简单的项目 结果访问的时候报了下面的错误,jsp本身很简单没有错误。 网上说删除掉项目lib下的jar包,但是我查看了之后项目lib下什么都没有,jar包并没有重复 麻烦大佬指点迷津 ![图片说明](https://img-ask.csdn.net/upload/201705/16/1494902073_90255.png)

SSH搭建框架报空指针异常

我在进行SSH基础框架搭建的时候(就是还没有配置实体类),只是进行了整合配置,将事务管理和数据库连接配置在spring中,spring代码如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  xmlns:jdbc="http://www.springframework.org/schema/jdbc"   xmlns:jee="http://www.springframework.org/schema/jee"  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"  xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> <!-- 开启扫描组件 --> <context:component-scan base-package="cn.itcast.oa"/> <context:property-placeholder location="classpath:db.properties"/> <!-- 配置sessionfactory --> <bean id="sessionFactory" > <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> </bean> <!-- 配置连接数据库 --> <bean id="datasource" > <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> <property name="driverClassName" value="${driverClassName}"/> </bean> <!-- 配置声明式事务管理(采用注解的方式) --> <!-- 配置事务管理器 --> <bean id="txManager" > <!-- 引用前边配置的SessionFactory --> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 注解驱动 --> <tx:annotation-driven transaction-manager="txManager"/>  </beans> 将sessionFactory中配置数据库连接的时候,就是<prorerty>中将数据库连接引进来的时候,就会报空指针异常,各位大牛能解答吗(纯自学SSH),环境是:Windows+Tomcat+oracle(虚拟机)

为什么我访问路径报出空指针异常(javaweb)

这是异常提示: java.lang.NullPointerException at java.io.FileOutputStream.<init>(FileOutputStream.java:206) at java.io.FileOutputStream.<init>(FileOutputStream.java:104) _**at com.mifan.web.UpLoadServlet.doGet(UpLoadServlet.java:41)_** at com.mifan.web.UpLoadServlet.doPost(UpLoadServlet.java:57) at javax.servlet.http.HttpServlet.service(HttpServlet.java:644) at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:285) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2439) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2428) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:722) 这是源代码: public class UpLoadServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try{ //创建工厂类 这是阿帕奇提供的那个第三包jar包 DiskFileItemFactory factory = new DiskFileItemFactory(); //生产文件上传核心类 ServletFileUpload fileUpload = new ServletFileUpload(factory); List<FileItem> list = fileUpload.parseRequest(request); //遍历所有的FileItem for(FileItem item : list){ if(item.isFormField()){ //当前是一个普通的字段项 String name = item.getFieldName();//普通字段的名字 String value = item.getString(); //普通字段名字所对应的值 System.out.println(name+":"+value); }else {//当前是一个文件上传项 //获取文件上传项的文件名 String filename = item.getName(); InputStream in = item.getInputStream(); OutputStream out = new FileOutputStream( this.getServletContext().getRealPath("upload/"+filename)); IOUtils.InAndOut(in, out); IOUtils.close(in, out); } } //利用文件上传核心类解析request }catch (Exception e) { e.printStackTrace(); } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }

一个空指针异常

jsp+servlet+javaBean做的个新闻发布 但是老是报一个空指针异常 数据库内有数据 业务:[code="java"] public LinkedList<News> list() { String sql = "select * from news order by id desc limit 0,5"; LinkedList<News> list = new LinkedList<News>(); MySQLConnection conn = ConnectionPool.getInstance().getConnection(); ResultSet rs = conn.Query(sql); System.out.println("this...................."); try { while (rs.next()) { News news = new News(rs.getInt(1), rs.getString(2), rs .getString(3), rs.getString(4), rs.getString(5)); list.add(news); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; }[/code] Servlet: [code="java"] public void list(HttpServletRequest req, HttpServletResponse res) { Bnews b = new Bnews(); List list = b.list(); req.setAttribute("list", list); try { res.sendRedirect("/jsp/index.jsp"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }[/code] 页面: [code="java"]<div class="inflist"> <% List list = (List) request.getAttribute("list"); News news = null; for(int i = 1;i<=list.size();i++) { news = (News)list.get(i); System.out.println(news.getTitle()+"tttttttt"); %> <div class="newsinf"> <div class="inftitle"> <a href="#"><%=news.getTitle()%></a> </div> [/code] 异常: [code="java"]type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Exception in JSP: /jsp/index.jsp:104 101: List list = (List) request.getAttribute("list"); 102: 103: News news = null; 104: System.out.println(news.getTitle()+"tttttttt"); 105: for(int i = 1;i<=list.size();i++) 106: { 107: news = (News)list.get(i); Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) root cause java.lang.NullPointerException org.apache.jsp.jsp.index_jsp._jspService(index_jsp.java:147) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) [/code] [b]问题补充:[/b] System.out.println(news.getTitle()+"tttttttt"); 删除 或者放在 news = (News)list.get(i); 后 再者 news = (News)list.get(i); 已经实例化 -------------------------------- Exception: [code="java"]org.apache.jasper.JasperException: Exception in JSP: /jsp/index.jsp:105 102: 103: News news = new News(); 104: 105: for(int i = 1;i<=list.size();i++) 106: { 107: news = (News)list.get(i); 108: System.out.println(news.getTitle()+"tttttttt"); Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) root cause java.lang.NullPointerException org.apache.jsp.jsp.index_jsp._jspService(index_jsp.java:148) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) [/code]

在运行一个初始化jsp页面时出现的空指针异常

有一个空指针的错误,大神帮忙解释一下啊!! type Exception report message java.lang.NullPointerException description The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: java.lang.NullPointerException org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:723) root cause java.lang.NullPointerException com.business.dbinstance.Access_token.reloadToken(Access_token.java:131) org.apache.jsp.init_jsp._jspService(init_jsp.java:81) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:723) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:723) note The full stack trace of the root cause is available in the Apache Tomcat/6.0.37 logs.

ssh框架,接口实现类调用service方法报空指针异常

``` //**实现类代码** String tname = saleName; String id = goodIds; //调用service层方法,传入两个参数。报空指针 int count = tpcCombinationSaleService.querySaleindexName(tname, id); //**service代码** public int querySaleindexName(String indexName,String id) throws com.sinovatech.common.exception.AppException; //**impl代码** @Override public int querySaleindexName(String indexName,String id) throws com.sinovatech.common.exception.AppException { indexName = indexName.trim(); String sql=""; if(!id.equals("")){ sql = "select * from DATA_RRYX.T_PC_COMBINATION_SALE Z where Z.NAME='" + indexName + "' and Z.id <> '"+id+"' and Z.is_delete = 'N'"; }else{ sql = "select * from DATA_RRYX.T_PC_COMBINATION_SALE Z where Z.NAME='" + indexName + "' and Z.is_delete = 'N'"; } return tpcCombinationSaleDAO.getRecordCountBySQL(sql); ``` 以上为代码,现在我运行测试类正常传参进去后,debug的时候走到调用service方法,没有走方法内部,就直接跳转到Thread类,的dispatchUncaughtException方法,然后就报了空指针异常,请问大佬们可能的原因是在哪里?

tomcat启动异常 空指针异常

严重: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to initialize component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[null]] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:188) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[null]] at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139) ... 6 more Caused by: java.lang.NullPointerException at org.apache.catalina.core.StandardContext.getObjectKeyPropertiesNameOnly(StandardContext.java:6464) at org.apache.catalina.core.StandardContext.getObjectNameKeyProperties(StandardContext.java:6445) at org.apache.catalina.util.LifecycleMBeanBase.initInternal(LifecycleMBeanBase.java:61) at org.apache.catalina.core.ContainerBase.initInternal(ContainerBase.java:1084) at org.apache.catalina.core.StandardContext.initInternal(StandardContext.java:6474) at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102) ... 7 more <Context> <Resource name="cubism" auth="Container" type="javax.sql.DataSource" username="cfms" password="cfms" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.1.254:3306/metrorcfms?characterEncoding=UTF-8" maxActive="50" maxIdle="10" testOnBorrow="true" validationQuery="select 1" timeBetweenEvictionRunsMillis="90000" /> </Context>

weblogic的Servlet创建之后,报空指针异常

各位前辈,帮忙一下 weblogic的Servlet创建之后,报空指针异常 但是找不出原因 所有代码如下:【只有一个servlet,且数据源配置正常,实验过了的,web.xml也配置完成】 ``` package myservlet; import java.awt.Container; import java.io.IOException; import java.io.PrintWriter; import java.sql.ResultSet; import java.util.Hashtable; import java.util.Properties; import java.util.Vector; import javax.activation.DataSource; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.spi.DirStateFactory.Result; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.mysql.jdbc.Connection; import com.mysql.jdbc.PreparedStatement; import com.mysql.jdbc.Statement; import com.mysql.jdbc.StatementImpl; import javax.naming.*; import javax.sql.*; import java.sql.*; import java.util.*; public class StudentServlet extends HttpServlet { public StudentServlet(){ super(); } public void destroy() { super.destroy(); } private static final String CONTENT_TYPE="text/html;charset=GBK"; //Do Get 方法 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); //打印网页 out.println("<HTML>"); out.println("<HEAD><TITLE>StudentServlet</TITLE></HEAD>"); out.println("<BODY bgcolor=\"#fffff\">"); if ((request.getParameter("sno"))==null ||(request.getParameter("sno")).equals("input number")){ out.println( "<form method='post' action='/lab05-2/src/myservlet/StudentServlet'>"); //"<form method='post' action='/lab05-2/StudentServlet'>"); out.println(""); out.println( "学号查询:<input type='text' name='sno' vaule='input number'/>"); out.println("<input type ='submit' vaule='查询'/><br>"); out.println("</form>"); } //另外一种情况 else if(!(request.getParameter("sno")).equals("input number")){ Vector vc =new Vector(); out.println("<Form method='post' action='/lab05-2/src/myservlet/StudentServlet'>"); out.println(""); out.println("学生学号:<input type='text' name='sno' />"); out.println("<input type ='submit' vaule='查询'/><br>"); out.println("</form>"); out.println("<hr>"); out.println("<table border='1'><tr>"); out.println("<th>学号</th><th>姓名</th><th>语文</th><th>数学</th></tr>"); try{ if((vc=accessDB(Integer.parseInt((String)request.getParameter("sno"))))!=null){ out.println("<tr>"); out.println("<td>"+vc.elementAt(0)+"</td>"); out.println("<td>"+vc.elementAt(1)+"</td>"); out.println("<td>"+vc.elementAt(2)+"</td>"); out.println("<td>"+vc.elementAt(3)+"</td>"); out.println("</tr>"); } }catch(Exception e) { out.println("<tr>"); out.println("<td>没有记录</td>"); out.println("</tr>"); out.println("<td>数据库里没有你要查询的记录</td>"); e.printStackTrace(); } out.println("</table>"); } out.println("</BODY>"); out.println("</HTML>"); out.flush(); out.close(); } //Do Post方法 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } //Init方法 public void init() throws ServletException { } //通过weblogic的JNDI服务来查询数据库数据 public Vector accessDB(int id){ Vector vc=new Vector(); Context ctx; javax.sql.DataSource ds = null; java.sql.Connection myConn = null ; final String JNDI_DATABASE_NAME="AA"; Properties ht =new Properties(); //Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL, "t3://localhost:7001"); try{ ctx = new InitialContext(ht); ds = (javax.sql.DataSource)ctx.lookup(JNDI_DATABASE_NAME); }catch(Exception e){ e.printStackTrace(); } if(ds == null){ System.out.println("Eorror !!!"); } else{ System.out.println("Connection is OK !!!"); } java.sql.PreparedStatement myStatement = null; ResultSet mySet = null; try{ myConn=ds.getConnection(); myStatement=myConn.prepareStatement("select * from stdb where sno=?"); myStatement.setInt(1, id); mySet=myStatement.executeQuery(); while (mySet.next()){ vc.add(Integer.toString(mySet.getInt("sno"))); vc.add(mySet.getString("sname")); vc.add(Integer.toString(mySet.getInt("chinese"))); vc.add(Integer.toString(mySet.getInt("math"))); } //关闭 myStatement.close(); mySet.close(); myConn.close(); return vc;//返回vc }catch(Exception e) { e.printStackTrace(); } return vc; } public static void main(String[] args) { StudentServlet aa=new StudentServlet(); System.out.println(aa.accessDB(100).elementAt(1)); } } ``` ![图片说明](https://img-ask.csdn.net/upload/201910/20/1571542376_553297.png) 【aa和student只是测试着用,与StudentServlet无关】 报错为: ![图片说明](https://img-ask.csdn.net/upload/201910/20/1571542511_665195.png) 大概就是这些,请指教, 初学,找过百度等也没有解决

空指针异常我怎么也找不出问题

java.lang.NullPointerException com.eshore.dao.ProductDaoImpl.findAll(ProductDaoImpl.java:33) com.eshore.service.ProductService.findAll(ProductService.java:36) org.apache.jsp.product_005flist2_jsp._jspService(product_005flist2_jsp.java:101) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 我是查询语句,JSP JDBC连接MYsql的,用DAO模式, 下面是报错里面这两句有问题的话的出处: 第一句:com.eshore.dao.ProductDaoImpl.findAll(ProductDaoImpl.java:33) public List<Product> findAll(String product_name) throws Exception{ List<Product> list = new ArrayList<Product>(); String sql = "select product_id,product_name,price,info from product"; if(product_name!=null&&!"".equals(product_name)){ sql = "select product_id,product_name,price,info from product where product_name like? "; this.pstmt.setString(1,"%" + product_name + "%"); } else { this.pstmt = this.conn.prepareStatement(sql); } ResultSet rs = this.pstmt.executeQuery(); Product product = null; while (rs.next()){ product = new Product(); product.setProduct_id(rs.getString(1)); product.setProduct_name(rs.getString(2)); product.setPrice(rs.getDouble(3)); product.setInfo(rs.getString(4)); list.add(product); } this.pstmt.close(); return list; } 标的是:this.pstmt.setString(1,"%" + product_name + "%");这句 第二句:com.eshore.service.ProductService.findAll(ProductService.java:36) public List<Product> findAll(String product_name) throws Exception{ List<Product> list = null; try{ list = this.dao.findAll(product_name); } catch (Exception e){ throw e; } finally { this.dbconn.close(); } return list; } 是里面的:list = this.dao.findAll(product_name); 在第二处可疑错中,我开始想是不是product_name是不是没判断非空, 加了if(product_name!=null&&!"".equals(product_name)){ 变成: try{ if(product_name!=null&&!"".equals(product_name)){ list = this.dao.findAll(product_name); }} 什么的还是报这个错: java.lang.NullPointerException com.eshore.dao.ProductDaoImpl.findAll(ProductDaoImpl.java:33) com.eshore.service.ProductService.findAll(ProductService.java:36)

没有找到空指针异常,求大神指导

org.apache.jasper.JasperException: An exception occurred processing JSP page /doSaveStudent.jsp at line 21 18: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 19: student.setBorn(sdf.parse(born)); 20: StudentDao sd = new StudentDao(); 21: if (sd.add(student)) { 22: request.setAttribute("msg", "娣诲姞鎴愬姛锛�"); 23: request.getRequestDispatcher("show.jsp").forward(request, 24: response); Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:575) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause java.lang.NullPointerException util.BaseDao.update(BaseDao.java:55) dao.ObjectDao.add(ObjectDao.java:17) org.apache.jsp.doSaveStudent_jsp._jspService(doSaveStudent_jsp.java:86) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

json传递到前端报空指针异常(前端使用的easyui)

如题 ``` @RequestMapping("/list") private String list() throws IOException{ List<User> list = userService.UserList(); String jsonString = JSON.toJSONString(list); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/json;charset=utf-8"); response.getWriter().write(jsonString); return "product"; } ``` ``` <table id="list"></table> <script type="text/javascript"> $('#list').datagrid({ url:'/list', columns:[[ { filed:'id', title:'用户编号', checkbox:true }, { filed:'name', title:'用户名称', width:200 }, { filed:'info', title:'用户简介', width:300 } ]], pagination:true }); </script> ```

java,请求出现空指针异常

## 控制台异常显示 1681496916525609________________1571436348402060 2017-6-9 9:43:07 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet riss2 threw exception java.lang.NullPointerException at cn.com.adtech.riss2.controller.platform.paper.PaperManagerController.metaform(PaperManagerController.java:224) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473) at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410) at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153) at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at cn.com.adtech.riss2.filter.jiaMiGouFilter.doFilter(jiaMiGouFilter.java:39) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at cn.com.adtech.riss2.filter.PaperLoginCheckFilter.doFilter(PaperLoginCheckFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) ## Java代码 / String deptOption = departementService.getDepartmentHtmlOption(ToolUnit.NullTo0(paper.getPpinPdepId())); String degreeOption = degreeService.getDegreeHtmlOption(ToolUnit.NullTo0(paper.getPpinPdegId())); //String subjectOption = resourceService.getSubjectOptions(ToolUnit.NullTo0(paper.getPpinRstyId()), 0L, "1"); String subjectOption = resourceService.getSubjectHtmlOption(0); Long teacherId = paper.getPpinSmanId(); System.out.println(teacherId+"________________"+paper.getPpinPdepId()); Long selectId = paper.getPpinPdepId(); //这一行报错 String teacherOption = teacherServce.getTeacherOption(selectId,teacherId); request.setAttribute("teacherOption", teacherOption); // request.setAttribute("deptOption", deptOption); request.setAttribute("degreeOption", degreeOption); request.setAttribute("subjectOption", subjectOption); session.setAttribute("paper", paper); request.setAttribute("submitStep", 2); return new ModelAndView("/platform/paper/updateMetaform"); } ## 数据执行 /** * 根据院系id获取审核导师html的select下拉列表 * @param 院系id * @param 若修改中导师已存在,则将该导师改为选中状态 * @return */ @Override public String getTeacherOption(long selectId,long teacherId) { String hql = "from SysManager sman where sman.smanType=" + SysManager.SMANTYPE_TEACHER +" and sman.smanDeptId="+selectId+ " order by sman.smanName asc"; List<SysManager> list = getHibernateTemplate().find(hql); if(list == null || list.size() < 1){ return ""; } System.out.println(teacherId+"_____________________"); StringBuffer buffer = new StringBuffer(""); SysManager sman = null; for(int i=0,s=list.size(); i < s; i++){ sman = list.get(i); if (teacherId > 0L && sman.getSmanId()==teacherId) { buffer.append("< option value='"+sman.getSmanId()+"' selected='selected' > "+sman.getSmanName()+" < /option > "); continue; } buffer.append("< option value='"+sman.getSmanId()+"' > "+sman.getSmanName()+"< /option >"); } String jsondata = buffer.toString(); list = null; buffer = null; return jsondata; } ## 说明 这个方法有两次调用,第一次做属于新增页面有一个选择导师的下拉列表,修改页面同样有,主要是为了获取列表,XML也是 配置了的,新增时能够进去,说明没有问题,修改进的是同一个方法结果报错,数据已展示,说明不是数据问题,在方法内打断点没反应,说明没有进,所以猜测是否因为(OncePerRequestFilter.java:76)没有配置字符集,求大神解决

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

Intellij IDEA 实用插件安利

1. 前言从2020 年 JVM 生态报告解读 可以看出Intellij IDEA 目前已经稳坐 Java IDE 头把交椅。而且统计得出付费用户已经超过了八成(国外统计)。IDEA 的...

搜狗输入法也在挑战国人的智商!

故事总是一个接着一个到来...上周写完《鲁大师已经彻底沦为一款垃圾流氓软件!》这篇文章之后,鲁大师的市场工作人员就找到了我,希望把这篇文章删除掉。经过一番沟通我先把这篇文章从公号中删除了...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

魂迁光刻,梦绕芯片,中芯国际终获ASML大型光刻机

据羊城晚报报道,近日中芯国际从荷兰进口的一台大型光刻机,顺利通过深圳出口加工区场站两道闸口进入厂区,中芯国际发表公告称该光刻机并非此前盛传的EUV光刻机,主要用于企业复工复产后的生产线扩容。 我们知道EUV主要用于7nm及以下制程的芯片制造,光刻机作为集成电路制造中最关键的设备,对芯片制作工艺有着决定性的影响,被誉为“超精密制造技术皇冠上的明珠”,根据之前中芯国际的公报,目...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

百度工程师,获利10万,判刑3年!

所有一夜暴富的方法都写在刑法中,但总有人心存侥幸。这些年互联网犯罪高发,一些工程师高技术犯罪更是引发关注。这两天,一个百度运维工程师的案例传遍朋友圈。1...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版(进大厂必备)

正确选择比瞎努力更重要!

字节跳动面试官竟然问了我JDBC?

轻松等回家通知

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

实时更新:计算机编程语言排行榜—TIOBE世界编程语言排行榜(2020年6月份最新版)

内容导航: 1、TIOBE排行榜 2、总榜(2020年6月份) 3、本月前三名 3.1、C 3.2、Java 3.3、Python 4、学习路线图 5、参考地址 1、TIOBE排行榜 TIOBE排行榜是根据全世界互联网上有经验的程序员、课程和第三方厂商的数量,并使用搜索引擎(如Google、Bing、Yahoo!)以及Wikipedia、Amazon、YouTube统计出排名数据。

立即提问
相关内容推荐