getSession出现空指针异常

ActionContext.getContext().getSession();直接报空指针异常
查资料好像是说session必须在Action里使用,因为我是做串口监听,查到数据准备保存到session里,所以报错了(ActionContext.getContext().getSession().put("screwObj",screwObj);报错),screwObj对象有值。
有大神知道具体是什么原因吗?要怎样弄才能存到session?
我是想把获取到的数据显示到页面上,准备用轮询读取session的值,有其它方法传值也行啊!!!

6个回答

现在回过来看来一下,发现这个问题还没答案,所以现在说一下我的解决办法.
因为我Session保存的是 串口对象 数据,原因是每次操作串口是需要打开串口对象的,而操作完了之后需要关闭对象,非常麻烦,所以想打开后,不关闭,把他保存在Session,等需要关闭时再取出来关闭,可测试时发现根本行不通,串口对象无法保存在Session,这一原因至今没找到.

但处理法法是,不保存串口对象,程序运行后一直读取数据,关闭程序时自然结束
Session保存的也不是串口对象,保存的是串口持续读取的数据,这个数据持续更新
相当于串口操作是底层,不会改变,中间是数据池,串口的数据持续更新数据池,当程序需要数据时直接在数据池取就行了

Action实现 servletRequestAware接口,然后从request对象获取session,然后传参传入到你的业务层,这样你就可以操作session了

你也可以直接用request返回到页面上使用啊

在页面获取request返回的数据,然后页面接着使用

ActionContext.getContext().getSession().put("screwObj",screwObj);
这里的空指针错误,有可能是ActionContext为空,有可能是ActionContext.getContext()为空,还有可能是ActionContext.getContext().getSession()为空,你定位了没,具体是哪个?

你的action配置文件和获取session的方法不对应,,没有看到你的action配置文件,所以不好说,看看这个人写的,,很详细
https://www.cnblogs.com/zhangzhifeng/p/4308331.html

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
hql查询时出现空指针异常
代码: ``` public Book findByBookNo(String bookNo) { // TODO Auto-generated method stub Session session = HibernateSessionFactory.getSession(); String hql="from Book as book where book.bookNo=:bookNo"; Query query =session.createSQLQuery(hql); query.setString("bookNo", bookNo); List<Book> books = query.list(); HibernateSessionFactory.closeSession(); if(books.size()>0){ return books.get(0); } else{ return null; } } ``` 出现空指针异常异常如下: ``` java.lang.NullPointerException com.Dao.BookDAOImpl.findByBookNo(BookDAOImpl.java:29) com.Service.BookServiceImpl.inputBook(BookServiceImpl.java:14) com.Action.BookInputAction.execute(BookInputAction.java:37) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.56 logs. ```
Sevlet监听器检测在线人数,出现空指针异常
监听器代码 public class UserCountListenerTest implements HttpSessionListener,ServletContextListener{ private int usercount; private ServletContext cxt; @Override public void contextDestroyed(ServletContextEvent arg0) { cxt = null; } public void contextInitialized(ServletContextEvent e) { cxt = e.getServletContext(); } public void sessionCreated(HttpSessionEvent arg0) { usercount++; cxt.setAttribute("usercount",new Integer(usercount)); } public void sessionDestroyed(HttpSessionEvent arg0) { usercount--; cxt.setAttribute("usercount",new Integer(usercount)); } } xml文件配置也没出错 下面是servlet代码 @WebServlet("/TestUserCount") public class TestUserCount extends HttpServlet { private static final long serialVersionUID = 1L; public TestUserCount() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext cxt = this.getServletContext(); HttpSession session = request.getSession(); int usercount = Integer.parseInt(cxt.getAttribute("usercount").toString()); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<meta charset=\"UTF-8\">"); out.println("<title>"); out.println("在线人数"); out.println("</title>"); out.println("</head>"); out.println("<body>"); out.println(usercount); out.println("</body>"); out.println("</html>"); out.close(); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } } 异常提示第27行(int usercount = Integer.parseInt(cxt.getAttribute("usercount").toString());)出现错误 java.lang.NullPointerException com.lzm.countlistener.TestUserCount.doGet(TestUserCount.java:27)
Query query =session.createSQLQuery(hql)查询时出现空指针异常
代码: ``` public Book findByBookNo(String bookNo) { // TODO Auto-generated method stub Session session = HibernateSessionFactory.getSession(); String hql="from Book as book where book.bookNo=:bookNo"; Query query =session.createSQLQuery(hql); //进行到这步就开始出错了 query.setString("bookNo", bookNo); List<Book> books = query.list(); HibernateSessionFactory.closeSession(); if(books.size()>0){ return books.get(0); } else{ return null; } } ``` 出现空指针异常异常如下: ``` java.lang.NullPointerException com.Dao.BookDAOImpl.findByBookNo(BookDAOImpl.java:29) com.Service.BookServiceImpl.inputBook(BookServiceImpl.java:14) com.Action.BookInputAction.execute(BookInputAction.java:37) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.56 logs. ```
JSP迭代器输出空指针异常
如下代码所示: ``` <% if (request.getSession().getAttribute("stus") != null) { List stus = (List) session.getAttribute("stus"); Iterator iter = stus.iterator(); //报错行 %> <table cellspacing="0" border="1px" align="center"> <tr><th>序号</th><th>学号</th><th>姓名</th><th>班级</th><th>修改</th><th>删除</th></tr> <% int i = 1; while(iter.hasNext()){ Student student = (Student) iter.next(); %> ``` 运行时该行抛出空指针异常,查看了Servlet类,也检查了这个JSP文件,不知道什么原因,请大神帮忙看下,哪儿出了问题?谢谢!
ssh封装了基类后出现空指针异常
<p> </p> <pre name="code" class="xml">&lt;bean id="baseDao" class="com.iwiz.dao.impl.BaseDaoImpl"&gt; &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="noteDao" class="com.iwiz.dao.impl.NoteDaoImpl" parent="baseDao"&gt;&lt;/bean&gt;</pre> <p> &lt;bean id="baseService" class="com.iwiz.service.impl.BaseServiceImpl"&gt;</p> <pre name="code" class="xml"> &lt;property name="baseDao" ref="baseDao"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="noteService" class="com.iwiz.service.impl.NoteServiceImpl" parent="baseService"&gt; &lt;property name="noteDao" ref="noteDao"&gt;&lt;/property&gt; &lt;/bean&gt;</pre> <p> public class BaseDaoImpl&lt;T, PK extends Serializable&gt; implements BaseDao&lt;T, PK&gt; {</p> <pre name="code" class="java"> private Class&lt;T&gt; entityClass; public BaseDaoImpl() { this.entityClass = null; Class&lt;T&gt; c = (Class&lt;T&gt;) getClass(); Type type = c.getGenericSuperclass(); if(type instanceof ParameterizedType) { Type[] parameterizedType = ((ParameterizedType)type).getActualTypeArguments(); this.entityClass = (Class&lt;T&gt;) parameterizedType[0]; } } public T findById(PK id) { return (T) getSession().load(<span style="color: #ff0000;">entityClass</span>, id); } }</pre> <p> public class NoteServiceImpl extends BaseServiceImpl&lt;Note, String&gt; implements NoteService {</p> <pre name="code" class="java"> private NoteDao noteDao; <span style="color: #ff0000;"> public void setBaseDao(NoteDao noteDao) { super.setBaseDao(noteDao); }</span> public void setNoteDao(NoteDao noteDao) { this.noteDao = noteDao; } }</pre> <p> tomcat在启动的时候并没有执行红色字体的代码,导致调用findById时entityClass为空值,但是BaseDaoImpl的构造方法已经把所需要的类都通过反射得到了呀,怎么回事呀?怎样才能让tomcat启动就能执行红色字体的代码?我漏了什么配置了还是...?</p>
数据库连接时总是空指针异常?测试表单信息无误,就是查询数据库时出错
java.lang.NullPointerException at com.Users.LoginServlet.doPost(LoginServlet.java:58) at javax.servlet.http.HttpServlet.service(HttpServlet.java:154) at javax.servlet.http.HttpServlet.service(HttpServlet.java:92) at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106) at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:173) at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:274) at com.caucho.server.port.TcpConnection.run(TcpConnection.java:514) at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:527) at com.caucho.util.ThreadPool.run(ThreadPool.java:449) at java.lang.Thread.run(Unknown Source) 源代码: package com.Users; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.Service.LoginService; /** * 登录控制层 : LoginServlet * 将用户个人信息保存到 Session范围内 * 根据status对页面进行分别显示 * @author daichen * */ public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; /* * 注入 LoginService 服务 */ private LoginService loginService; @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { doGet(req,res); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("GBK"); response.setCharacterEncoding("GBK"); User user = null; // 获取表单提交的登录信息 String userId = null; String password = null; userId = request.getParameter("userId"); password = request.getParameter("password"); // 先判断用户信息是否否为空 if(userId == null || "".equals(userId) || password == null || "".equals(password)) { // 用户信息有误 , 回到 login.jsp 页面 response.getWriter().println("<html><h3><font color='#f00'>对不起,你输入的信息有误 .请重新确认!</h3></font></html>"); return; } else { // 到数据表 user 中查找该用户 , 返回一个 User 对象 System.out.println(userId+" "+password); user = loginService.userLogin(userId,password); // 并对查询到的结果进行处理 if(user != null) { // 获取请求域的session对象 HttpSession session = request.getSession(); // 对三种权限分开添加到 Session 域中 if(user.getStatus() == 0){ session.setAttribute("geneUser", user); } if(user.getStatus() == 1){ session.setAttribute("admin", user); } if(user.getStatus() == 2){ session.setAttribute("superAdmin", user); } // 成功获取到用户信息 , 转到 index.jsp RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsp/index.jsp"); rd.forward(request, response); return; } else { // 查询没有该用户 , 转到 login.jsp response.getWriter().print("<h3><font color='#f00'>对不起,你还未注册用户 </h3></font>" + userId + "<h3><font color='#f00'>请先前去注册!</h3></font>"); RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/jsp/register.jsp"); rd.forward(request, response); return; } } } }
timer定时器报空指针异常为什么?
今天想到用timer写一个定时清空session值得定时器,但报空指针。 代码如下: ``` public void removeYZM( HttpServletRequest request, String code) { Timer timer = new Timer(); System.out.println("验证码:------"+request.getSession().getAttribute(code)); timer.schedule(new TimerTask() { public void run() { // 删除session中存的验证码 request.getSession().removeAttribute(code); timer.cancel(); } }, 1 * 60 * 1000); } ``` 报错信息 ``` Exception in thread "Timer-1" java.lang.NullPointerException at com.temp.ssm.controller.UserClientController$1.run(UserClientController.java:51) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505) ```
Javaweb项目获取信息是如果先登录管理员查看用户信息就报空指针异常
Javaweb项目获取信息是如果先登录管理员查看用户信息就报空指针异常,如果先登其他用户再登管理员查看信息则只显示之前登录的用户信息 public String userlist(){ HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); Students students = (Students)session.getAttribute("students"); String username = request.getParameter("username"); StringBuffer sb = new StringBuffer(); sb.append(" where "); if(username !=null &&!"".equals(username)){ sb.append(" username like '%"+username+"%' "); request.setAttribute("username", username); } if(students.getRole()==2){ sb.append(" stuid="+students.getStuid()+" and deletestatus=0 order by id desc ");//降序查询,ASC } if(students.getRole()==1){ sb.append(" role=2 and deletestatus=0 order by id desc ");//降序查询,ASC } if(students.getRole()==3){ sb.append(" role=2 and deletestatus=0 order by id desc "); } String where = sb.toString(); int currentpage = 1; int pagesize = 10; if(request.getParameter("pagenum") != null){ currentpage = Integer.parseInt(request.getParameter("pagenum")); } long total = studentsDao.selectBeanCount(where.replaceAll("order by id desc", "")); List<Students> list = studentsDao.selectBeanList((currentpage-1)*pagesize, pagesize, where); request.setAttribute("list", list); String pagerinfo = Pager.getPagerNormal((int)total, pagesize, currentpage, "method!userlist", "共有"+total+"条记录"); request.setAttribute("pagerinfo", pagerinfo);
JSCH上传文件到linux服务器打开远程目录报空指针异常
最近的项目要用jsch把本地文件上传到服务器,但是出现问题: ``` public static void main(String[] args) { try { upload("/home/informix", "C:\\Users\\Administrator\\Desktop\\upload.jsp", getSession()); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSchException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SftpException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //获得指定用户session public static Session getSession() throws JSchException { JSch jsch = new JSch();// 创建JSch对象 Session session = jsch.getSession("informix", "192.168.226.166", 22); session.setPassword("ffcsffcs"); Properties config = new Properties(); // 设置 SSH 连接时不进行公钥确认 config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); return session; } //上传单个文件 public static void upload(String remotePath, String uploadFile, Session session) throws JSchException, FileNotFoundException, SftpException { ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp"); channelSftp.cd(remotePath); File file = new File(uploadFile); channelSftp.put(new FileInputStream(file), file.getName()); //channelSftp.put(new FileInputStream(file), remotePath, ChannelSftp.OVERWRITE); System.out.println("Upload Success!"); } ``` 异常: 4: at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:285) at cn.ffcs.util.JSchUtils.upload(JSchUtils.java:121) at cn.ffcs.util.JSchUtils.main(JSchUtils.java:29) Caused by: java.lang.NullPointerException at com.jcraft.jsch.Packet.reset(Packet.java:43) at com.jcraft.jsch.ChannelSftp.sendPacketPath(ChannelSftp.java:2025) at com.jcraft.jsch.ChannelSftp.sendREALPATH(ChannelSftp.java:1954) at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:1807) at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:268) ... 2 more 求大神指点
求大神帮忙啊,空指针异常怎么解决,代码如下
就是不能用get方法读取到数据库里面的email值,要怎么解决 User db_user=(User)session.get(User.class, user.getEmail());//这句话不行 public boolean CheckLogin(User user) { Session session =null; try{ session=HibernateSessionFactory.getSession(); User db_user=(User)session.get(User.class, user.getEmail()); if(db_user==null){ this.errMessage="帐号不存在"; System.out.println(this.errMessage); return false; }else if(!db_user.getPassword().equals(user.getPassword())){ this.errMessage="密码不正确"; System.out.println(this.errMessage); return false; } }finally{ HibernateSessionFactory.closeSession(); } return true; } } ![图片说明](https://img-ask.csdn.net/upload/201603/24/1458784911_174655.png)
空指针异常,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'
空指针的异常没有找出来,求解
1. package com.bjsxt.utils; import org.hibernate.Hibernate; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass; import org.omg.CORBA.PRIVATE_MEMBER; import oracle.net.aso.f; public class HibernateUtil { private static String HIBERNATE_CONFIG_FILE = "hibernate.cfg.xml"; private static SessionFactory sessionFactory = null; private static ThreadLocal<Session> tl = new ThreadLocal<>(); private static Configuration configure = null; static{ try { configure = new Configuration().configure("HIBERNATE_CONFIG_FILE"); } catch (Exception e) { e.printStackTrace(); System.out.println("核心装置安装失败"); } try { sessionFactory = configure.buildSessionFactory(); } catch (Exception e) { e.printStackTrace(); System.out.println("C区以安放!"); } } private HibernateUtil(){ } /** * 获取session * @return */ public static Session getsession(){ Session session = tl.get(); if(session == null){ session = sessionFactory.openSession();----这块是报异常的地方 tl.set(session); } return session; } /** * 关闭session */ public static void closeSession(){ Session session = tl.get(); tl.set(null); if(session != null){ session.close(); } } } 2.![图片说明](https://img-ask.csdn.net/upload/201708/24/1503555931_523098.png) 3.![图片说明](https://img-ask.csdn.net/upload/201708/24/1503555952_89058.png) 不知道哪里来的空指针异常求解 发现问题了,就是sessionFactory是null,说是hibernate.cfg.xml没有用到,这是怎么回事? The value of the field HibernateUtil.HIBERNATE_CONFIG_FILE is not used。。怎么改?
Hiberate 用detached作子查询 报空指针异常
``` DetachedCriteria dc = DetachedCriteria.forClass(Course.class); DetachedCriteria subselect = DetachedCriteria.forClass(CoursePlan.class) .add(Restrictions.eq("schoolYear", schoolYear)); dc.add(Property.forName("id").notIn(subselect)); return this.getSession().createCriteria(Course.class).add(Property.forName("id").notIn(subselect)).list(); ``` at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:362) at org.hibernate.criterion.SubqueryExpression.createAndSetInnerQuery(SubqueryExpression.java:153) at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:69) at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:380) at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:113) at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82) at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:92) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1697) at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347) at com.esmis.dao.impl.CourseDaoImpl.findSchoolYearCourses(CourseDaoImpl.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy7.findSchoolYearCourses(Unknown Source) at com.esmis.service.impl.CourseServiceImpl.getSchoolYearCourse(CourseServiceImpl.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34) at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428) at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431) at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283) at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52) at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101) at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146) at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 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 com.esmis.filter.TimeOutFilter.doFilter(TimeOutFilter.java:42) 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:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2440) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2429) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)
求大神指点,struts1提交form报空指针异常,连过滤器的init方法都没有执行
javax.servlet.ServletException: java.lang.NullPointerException org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) javax.servlet.http.HttpServlet.service(HttpServlet.java:646) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) cd.itcast.util.SessionViewFilter.doFilter(SessionViewFilter.java:38) root cause java.lang.NullPointerException java.lang.Class.isAssignableFrom(Native Method) org.apache.struts.util.RequestUtils.rationalizeMultipleFileProperty(RequestUtils.java:506) org.apache.struts.util.RequestUtils.populate(RequestUtils.java:459) org.apache.struts.chain.commands.servlet.PopulateActionForm.populate(PopulateActionForm.java:50) org.apache.struts.chain.commands.AbstractPopulateActionForm.execute(AbstractPopulateActionForm.java:60) org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) javax.servlet.http.HttpServlet.service(HttpServlet.java:646) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) cd.itcast.util.SessionViewFilter.doFilter(SessionViewFilter.java:38) 代码如下 reg.jsp <body> <form action="/user.do?method=save" method="post" id="signupForm" enctype="multipart/form-data"> <input type="hidden" name="method" value="save"> <table width="70%" cellpadding="0" border="1"> <tr> <td>登录名</td> <td><input type="text" name="loginName" ></td> </tr> <tr> <td>密码</td> <td><input type="password" name="password" id="password"></td> </tr> <tr> <td>确认密码</td> <td><input type="password" name="repassword"></td> </tr> <tr> <td>性别</td> <td><input type="radio" name="sex" checked="checked" >男 <input type="radio" name="sex" >女</td> </tr> <tr> <td>昵称</td> <td><input type="text" name="nickName"></td> </tr> <tr> <td>邮箱</td> <td><input type="text" name="email"></td> </tr> <tr> <td>出生日期</td> <td><input type="text" name="brithday"></td> </tr> <tr> <td>头像</td> <td><input type="file" name="picture"></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="注册"> <input type="reset" value="重置"> <input type="reset" value="返回" onclick="javascript:window.history.go(-1)" > <input type="reset" value="返回首页" onclick="javascript:window.location='/bbsdir.do?method=list'" > </td> </tr> </table> </form> </body> UserForm get set 方法没贴上来 private String loginName; private String password; private String sex; private String nickName; private String email; private Date brithday; private FormFile picture; sessionfilter @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub Session session = null; Transaction transaction = null; try { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); session = HibernateUtil.getSession(); transaction = session.beginTransaction(); chain.doFilter(request, response); transaction.commit(); } catch (HibernateException e) { // TODO Auto-generated catch block transaction.rollback(); e.printStackTrace(); } finally { HibernateUtil.closeSession(); } } public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub DateConverter dateConverter = new DateConverter(); String[] pattern=new String[]{"yy-MM-dd","yyyy年MM月dd日"}; dateConverter.setPatterns(pattern); ConvertUtils.register(dateConverter, Date.class); System.out.println("日期转换器注册成功"); }
SpringMVC+hibernate4+Extjs4.2+mysql(空指针异常)
@ResponseBody @RequestMapping("/daochu.do") public Object daochu(String id,HttpServletRequest request)throws Exception{ String ids=id.replaceAll(",", "','"); //System.out.println(ids); //根据两个id同时查询两条语句 String hql="FROM WorkOrders WHERE id IN ('"+ids+"')"; //String hql="FROM WorkOrders w where w.id=?"; //System.out.println(ids); System.out.println(id); Query query=sessionFactory.openSession().createQuery(hql); //query.setString(0, id); List list=query.list(); Iterator i=list.iterator(); Workbook wb=new HSSFWorkbook(); Sheet sheet=wb.createSheet("第一个sheet页"); int m=0; int n=0; while(i.hasNext()){ WorkOrders user = (WorkOrders) i.next(); Row row=sheet.createRow(m); Cell cell1=row.createCell(0); Cell cell2=row.createCell(1); Cell cell3=row.createCell(2); Cell cell4=row.createCell(3); Cell cell5=row.createCell(4); Cell cell6=row.createCell(5); Cell cell7=row.createCell(6); cell1.setCellValue(user.getId()); cell2.setCellValue(user.getFailuretime()); cell3.setCellValue(user.getFailureaddress()); cell4.setCellValue(user.getRepairtime()); cell5.setCellValue(user.getMaintenanceman()); cell6.setCellValue(user.getCompletion()); cell7.setCellValue(user.getFailurecontent()); m++; } String fileName="sss.xls"; String path=request.getSession().getServletContext().getRealPath("/")+"file"+"\\"+fileName;// .servletContext.getRealPath(""); System.out.println(path); //在该位置导出excel文件 //F:\lr_space\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\SpringMVC2\file FileOutputStream fileOut=new FileOutputStream(path); wb.write(fileOut); fileOut.close(); return "success"; } ---------- 前台的页面Extjs export_Item:function(button){ var grid=button.up('globalStatisticsView') var data =grid.getSelectionModel().getSelection(); if(data.length==0){ Ext.Msg.alert("提示","您至少选择一条数据") }else{ //1.先得到ID的数据(name) var st=grid.getStore(); var ids=[]; Ext.Array.each(data,function(record){ ids.push(record.get('id')); }); //2.后台操作 Ext.Ajax.request({ params:{ids:ids.join(",")}, url:'gdgl/daochu.do?id='+ ids, method:'POST', timeout:2000, async:false, success:function(response,opts){ Ext.Array.each(data,function(record){ st.getById(record); //st.removeAll(record); }); } }); Ext.Msg.alert("报表成功导出","<font color='green'>报表导出成功!谢谢!<font>"); } }, ---------- 报出的异常错误是: 5,6 十二月 25, 2013 10:57:36 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet spring threw exception java.lang.NullPointerException at cn.com.cisec.hnjt.control.WorkOrdersController.daochu(WorkOrdersController.java:114) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838) at javax.servlet.http.HttpServlet.service(HttpServlet.java:643) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 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:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source) ---------- 还有火狐调试的时候发现POST传值去后台时会发生 POST daochu.do?id=5,6 500 Internal Server Error 127.0.0.1:8080 3.4 KB 127.0.0.1:8080
spring mvc 在请求服务时报400异常在浏览器上重新发送链接进入请求的方法又报空指针异常
1. //拦截器 2. @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception { System.out.println( request.getRequestedSessionId()); System.out.println(request.getSession().getAttribute("sessionId")+"+++++++"); if(request.getRequestedSessionId().equals(request.getSession().getAttribute("sessionId"))){ return true; } return false; } @Controller @RequestMapping("/back/html/") public class GoodsAction { //请求的方法 @RequestMapping("addGoods") public void addGoods(Goods goods,MultipartFile goodsImg,HttpServletRequest request){ System.out.println("__________________________________________"); String uploda="uplode/"; File file=new File(uploda, UUID.randomUUID()+".jpg"); try { goodsImg.transferTo(file); } catch (IllegalStateException | IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } } //jsp的file <input type="file" name="goodsImg" size="30"> ![图片说明](https://img-ask.csdn.net/upload/201704/18/1492483320_35968.png)
session过期后,这段代码报空指针异常 如何修改
[code="java"] public String logoff() throws Exception { HttpSession session = request.getSession(false); session.removeAttribute("SE_SEIMEI"); session.removeAttribute("SE_MAIL"); session.removeAttribute(update_date); session.invalidate(); id = null; mail = null; return "logoff"; }[/code]
spring 注解 空指针错误
先贴异常吧: [code="java"]cn.buct.inteWeb.user.web.LoginAction.login(LoginAction.java:52) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) java.lang.Thread.run(Unknown Source)[/code] 下面是代码 [code="java"] package cn.buct.inteWeb.user.web; import javax.annotation.Resource; import org.apache.commons.lang.StringUtils; import cn.buct.inteWeb.common.web.AbstractAjaxAction; import cn.buct.inteWeb.user.entity.User; import cn.buct.inteWeb.user.service.UserManager; import cn.buct.inteWeb.Constants; import cn.buct.inteWeb.SessionHolder; public class LoginAction extends AbstractAjaxAction <User,Long>{ private static final long serialVersionUID = 1L; private UserManager userManager; private static final String USER_LOGIN = "index"; private String userName; private String password; private String message; public String login() { String userName2 = getRequest().getParameter("userName"); System.out.println("userName=" + userName2); String password2 = getRequest().getParameter("password"); System.out.println("password=" + password2); System.out.println(userManager); /** * 判断当前是否已经登录 */ if(SessionHolder.isLogined(getRequest())) { return USER_LOGIN; } /** * 登录验证码显示控制begin */ long count = 1; if (null != getRequest().getSession() && null != getRequest().getSession().getAttribute("count")) { count = ((Long) getRequest().getSession().getAttribute("count")) + 1; } getRequest().getSession().setAttribute("count", count); if (StringUtils.isBlank(userName) && StringUtils.isNotBlank(getRequest().getParameter("userName"))) { userName = getRequest().getParameter("userName").trim(); } // 判断用户是否存在 User user = userManager.getByName(userName); if (user == null) { message = Constants.LOGIN_USER_ERROR_MSG; return USER_LOGIN; } return null; } public String loginInput() { return USER_LOGIN; } @Override protected BaseEntityManager<User, Long> getManager() { // TODO Auto-generated method stub return null; } @Override protected Long getId() { // TODO Auto-generated method stub return null; } public void setUserManager(UserManager userManager) { this.userManager = userManager; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } [/code] web.xml文件: [code="xml"] <?xml version="1.0" encoding="UTF-8"?> <web-app id="contact" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>test</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> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:spring/applicationContext.xml classpath*:spring/modules/applicationContext*.xml classpath*:spring/modules/applicationContext-dnsis-soa.xml <!-- classpath*:spring/modules/applicationContext-quartz-client.xml --> </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!-- encodingFilter--> <filter> <filter-name>encodingFilter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- struts2Filter--> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>cn.buct</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <session-config> <session-timeout>20</session-timeout> </session-config> </web-app> [/code] struts.xml [code="xml"] <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.custom.i18n.resources" value="messageResource" /> <constant name="struts.multipart.maxSize" value="1000000000" /> <!-- <constant name="struts-devMode" Value="true"> --> <constant name="struts.devMode" value="true"/> <package name="user" extends="struts-default" namespace="/user"> <action name="Login" class="cn.buct.inteWeb.user.web.LoginAction"> <result name="index">/view/user-login.jsp</result> </action> </package> </struts> [/code] applicationContext.xml [code="xml"] <?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default-lazy-init="true" default-autowire="byName"> <description></description> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" lazy-init="false"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_NEVER" /> <property name="ignoreResourceNotFound" value="true" /> <property name="order" value="1" /> <property name="ignoreUnresolvablePlaceholders" value="true" /> <property name="locations"> <list> <value>classpath:application.properties</value> </list> </property> </bean> <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 --> <context:component-scan base-package="cn.knet" /> <!-- 使用aop定义事务 --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* cn.knet.dnsis.*.service.*.*(..))" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="select*" read-only="true" /> <tx:method name="*" /> </tx:attributes> </tx:advice> <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="maxActive" value="30" /> </bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="classpath:ibatis/SqlMapConfig.xml" /> </bean> <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate" /> <!-- freemarker template engine --> <bean id="templateEngine" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="freemarkerSettings"> <props> <prop key="template_update_delay">0</prop> <prop key="default_encoding">UTF-8</prop> <prop key="locale">zh_CN</prop> </props> </property> </bean> </beans> [/code] 麻烦多指教了。
Struts2在Action中取Session中值的迷茫
我在LoginActon 中用 [code="java"]ServletActionContext.getRequest().getSession().setAttribute("user",user);[/code] 传递的User对象 在另外Action取User,用 [code="java"]User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user");[/code] 好像只能在public String execute()方法中能得到 而在该Action中的另外方法不能得到,老是返回空指针异常 希望哪位大侠能指点下迷津
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看...
阿里P8数据架构师:顶级开发者都在用什么数据库?
其实从去年已经隐隐约约感觉到数据库的有变化,只是没有想到变得这么快。今年的一些事情实实在在地给了某些数据库重击,如果以前去某数据库还是喊喊,然后该用还用,今年从传统领域刮起的去某数据库的风,已经开始了,并且后面的乌云密布也看得见。 最近看一篇国外的开源产品提供厂商的一篇文字,主要是在询问了他的几百位客户后得出了下图中的2019年数据库的使用趋势。 从图中可以看出,MySQL以38.9...
面试官:关于Java性能优化,你有什么技巧
通过使用一些辅助性工具来找到程序中的瓶颈,然后就可以对瓶颈部分的代码进行优化。 一般有两种方案:即优化代码或更改设计方法。我们一般会选择后者,因为不去调用以下代码要比调用一些优化的代码更能提高程序的性能。而一个设计良好的程序能够精简代码,从而提高性能。 下面将提供一些在JAVA程序的设计和编码中,为了能够提高JAVA程序的性能,而经常采用的一些方法和技巧。 1.对象的生成和大小的调整。 J...
互联网公司分布式系统架构演进之路
介绍 分布式和集群的概念经常被搞混,现在一句话让你明白两者的区别。 分布式:一个业务拆分成多个子业务,部署在不同的服务器上 集群:同一个业务,部署在多个服务器上 例如:电商系统可以拆分成商品,订单,用户等子系统。这就是分布式,而为了应对并发,同时部署好几个用户系统,这就是集群 1 单应用架构 2 应用服务器和数据库服务器分离 单机负载越来越来,所以要将应用服务器和数据库服务器分离 3 应用服务...
【图解算法面试】记一次面试:说说游戏中的敏感词过滤是如何实现的?
版权声明:本文为苦逼的码农原创。未经同意禁止任何形式转载,特别是那些复制粘贴到别的平台的,否则,必定追究。欢迎大家多多转发,谢谢。 小秋今天去面试了,面试官问了一个与敏感词过滤算法相关的问题,然而小秋对敏感词过滤算法一点也没听说过。于是,有了下下事情的发生… 面试官开怼 面试官:玩过王者荣耀吧?了解过敏感词过滤吗?,例如在游戏里,如果我们发送“你在干嘛?麻痹演员啊你?”,由于“麻痹”是一个敏感词,...
程序员需要了解的硬核知识之汇编语言(一)
之前的系列文章从 CPU 和内存方面简单介绍了一下汇编语言,但是还没有系统的了解一下汇编语言,汇编语言作为第二代计算机语言,会用一些容易理解和记忆的字母,单词来代替一个特定的指令,作为高级编程语言的基础,有必要系统的了解一下汇编语言,那么本篇文章希望大家跟我一起来了解一下汇编语言。 汇编语言和本地代码 我们在之前的文章中探讨过,计算机 CPU 只能运行本地代码(机器语言)程序,用 C 语言等高级语...
OpenCV-Python 绘图功能 | 七
目标 学习使用OpenCV绘制不同的几何形状 您将学习以下功能:cv.line(),cv.circle(),cv.rectangle(),cv.ellipse(),cv.putText()等。 代码 在上述所有功能中,您将看到一些常见的参数,如下所示: img:您要绘制形状的图像 color:形状的颜色。对于BGR,将其作为元组传递,例如:(255,0,0)对于蓝色。对于灰度,只需传递...
GitHub 标星 1.6w+,我发现了一个宝藏项目,作为编程新手有福了!
大家好,我是 Rocky0429,一个最近老在 GitHub 上闲逛的蒟蒻… 特别惭愧的是,虽然我很早就知道 GitHub,但是学会逛 GitHub 的时间特别晚。当时一方面是因为菜,看着这种全是英文的东西难受,不知道该怎么去玩,另一方面是一直在搞 ACM,没有做一些工程类的项目,所以想当然的以为和 GitHub 也没什么关系(当然这种想法是错误的)。 后来自己花了一个星期看完了 Pyt...
Java知识体系最强总结(2020版)
更新于2019-12-15 10:38:00 本人从事Java开发已多年,平时有记录问题解决方案和总结知识点的习惯,整理了一些有关Java的知识体系,这不是最终版,会不定期的更新。也算是记录自己在从事编程工作的成长足迹,通过博客可以促进博主与阅读者的共同进步,结交更多志同道合的朋友。特此分享给大家,本人见识有限,写的博客难免有错误或者疏忽的地方,还望各位大佬指点,在此表示感激不尽。 文章目录...
计算机专业的书普遍都这么贵,你们都是怎么获取资源的?
介绍几个可以下载编程电子书籍的网站。 1.Github Github上编程书资源很多,你可以根据类型和语言去搜索。推荐几个热门的: free-programming-books-zh_CN:58K 星的GitHub,编程语言、WEB、函数、大数据、操作系统、在线课程、数据库相关书籍应有尽有,共有几百本。 Go语言高级编程:涵盖CGO,Go汇编语言,RPC实现,Protobuf插件实现,Web框架实...
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
Fiddler+夜神模拟器进行APP抓包
Fiddler+夜神模拟器进行APP抓包 作者:霞落满天 需求:对公司APP进行抓包获取详细的接口信息,这是现在开发必备的。 工具:Fiddler抓包,夜神模拟器 模拟手机 安装APP 1.下载Fiddler https://www.telerik.com/download/fiddler Fiddler正是在这里帮助您记录计算机和Internet之间传递的所有HTTP和HTTPS通信...
小白学 Python 爬虫(42):春节去哪里玩(系列终篇)
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Linux基础入门 小白学 Python 爬虫(4):前置准备(三)Docker基础入门 小白学 Python 爬虫(5):前置准备(四)数据库基础 小白学 Python 爬虫(6):前置准备(...
一文带你看清 HTTP 所有概念
上一篇文章我们大致讲解了一下 HTTP 的基本特征和使用,大家反响很不错,那么本篇文章我们就来深究一下 HTTP 的特性。我们接着上篇文章没有说完的 HTTP 标头继续来介绍(此篇文章会介绍所有标头的概念,但没有深入底层) HTTP 标头 先来回顾一下 HTTP1.1 标头都有哪几种 HTTP 1.1 的标头主要分为四种,通用标头、实体标头、请求标头、响应标头,现在我们来对这几种标头进行介绍 通用...
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东...
破14亿,Python分析我国存在哪些人口危机!
一、背景 二、爬取数据 三、数据分析 1、总人口 2、男女人口比例 3、人口城镇化 4、人口增长率 5、人口老化(抚养比) 6、各省人口 7、世界人口 四、遇到的问题 遇到的问题 1、数据分页,需要获取从1949-2018年数据,观察到有近20年参数:LAST20,由此推测获取近70年的参数可设置为:LAST70 2、2019年数据没有放上去,可以手动添加上去 3、将数据进行 行列转换 4、列名...
在家远程办公效率低?那你一定要收好这个「在家办公」神器!
相信大家都已经收到国务院延长春节假期的消息,接下来,在家远程办公可能将会持续一段时间。 但是问题来了。远程办公不是人在电脑前就当坐班了,相反,对于沟通效率,文件协作,以及信息安全都有着极高的要求。有着非常多的挑战,比如: 1在异地互相不见面的会议上,如何提高沟通效率? 2文件之间的来往反馈如何做到及时性?如何保证信息安全? 3如何规划安排每天工作,以及如何进行成果验收? ...... ...
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。 再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。 下文是原回答,希望能对你能有所启发。 如果我说,这个世界上人真的分三六九等,...
[数据结构与算法] 排序算法之归并排序与基数排序
归并排序 归并排序(MERGE-SORT)是利用归并的思想实现的排序方法,该算法采用经典的分治(divide-and-conquer)策略(分治法将问题分(divide)成一些小的问题然后递归求解,而治(conquer)的阶段则将分的阶段得到的各答案"修补"在一起,即分而治之)。 基本思想 可以看到这种结构很像一棵完全二叉树,本文的归并排序我们采用递归去实现(也可采用迭代的方式去实现)。分阶段可以...
B 站上有哪些很好的学习资源?
哇说起B站,在小九眼里就是宝藏般的存在,放年假宅在家时一天刷6、7个小时不在话下,更别提今年的跨年晚会,我简直是跪着看完的!! 最早大家聚在在B站是为了追番,再后来我在上面刷欧美新歌和漂亮小姐姐的舞蹈视频,最近两年我和周围的朋友们已经把B站当作学习教室了,而且学习成本还免费,真是个励志的好平台ヽ(.◕ฺˇд ˇ◕ฺ;)ノ 下面我们就来盘点一下B站上优质的学习资源: 综合类 Oeasy: 综合...
史上最牛逼的 Eclipse 快捷键,提高开发效率!
如果你在使用IDEA,请参考博主另外的一篇idea快捷键的博客。
相关热词 c#时间格式化 不带- c#替换字符串中指定位置 c# rdlc 动态报表 c# 获取txt编码格式 c#事件主动调用 c#抽象工厂模式 c# 如何添加类注释 c# static块 c#处理浮点数 c# 生成字母数字随机数
立即提问