它只会在我第一次运行我的页面或重新启动glassfish服务器时发生,我甚至可以关闭页面并再次打开它,它不会显示异常和空白页面,直到我重新启动glassfish并再次运行它。日志显示一些行,但这些行没有代码,所以我真的不知道什么是问题,因为我已经检查了一个我没有任何空变量。 这里是日志(如果您需要代码,请告诉我): 编辑:我真的不明白为什么我得到了投票,我尽可能地清楚地说明了并给了日志代码。
Warning: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.Header_jsp._jspService(Header_jsp.java:57)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:695)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:626)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:977)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:48)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)
Warning: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.Header_jsp._jspService(Header_jsp.java:57)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:695)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:626)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:977)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:48)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)
这里的代码显然是异常:
<%@page language="java" %>
<%@page import="com.crimsonlogic.actors.SgcBean"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="com.crimsonlogic.databaseBeans.Login"%>
<%
SgcBean.counterdeH++;
HttpSession session2 = request.getSession();
Cookie[] g = request.getCookies();
Cookie cookie = new Cookie("tipo", "");
Cookie cuser = null;
if (g.length > 0) {
for (Cookie c : g) {
System.out.println(c.getName() + " " + c.getValue());
if (c != null) {
if (c.getName().compareTo("tipo") == 0) {
cookie.setValue(c.getValue());
}
if (c.getName().compareTo("usuario") == 0) {
cuser = c;
}
}
}
}
if ((cookie.getValue().compareTo("") == 0 || SgcBean.counterdeH < 2)) {
session2.setAttribute("tipo", "U");
cookie.setValue("U");
System.out.println("Se esta ejecutando porque es null");
} else {
session2.setAttribute("tipo", cookie.getValue().substring(0, 1).toString());
System.out.println("Se esta imprimiendo porque no es null " + cookie.getValue().substring(0, 1).toString());
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>VUDA</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content=""/>
<meta property="og:image" content=""/>
<meta property="og:url" content=""/>
<meta property="og:site_name" content=""/>
<meta property="og:description" content=""/>
<meta name="twitter:title" content="" />
<meta name="twitter:image" content="" />
<meta name="twitter:url" content="" />
<meta name="twitter:card" content="" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,700" rel="stylesheet">
<!-- Animate.css -->
<link rel="stylesheet" href="css/animate.css">
<!-- Icomoon Icon Fonts-->
<link rel="stylesheet" href="css/icomoon.css">
<!-- Themify Icons-->
<link rel="stylesheet" href="css/themify-icons.css">
<!-- Magnific Popup -->
<link rel="stylesheet" href="css/magnific-popup.css">
<!-- Owl Carousel -->
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/owl.theme.default.min.css">
<!--Gritter-->
<link rel="stylesheet" href="css/magnific-popup.css">
<!-- Theme style -->
<link rel="stylesheet" href="css/style.css">
<!--Obras css-->
<link rel="stylesheet" href="css/obras.css">
<!--modal-->
<link rel="stylesheet" href="css/modalDelete.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Roboto/Varela+Round" rel="stylesheet">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<!--bootstrap-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- tabs-->
<link rel="stylesheet" type="text/css" href="http://vtimbuc.github.io/bootstrap-responsive-tabs/dist/css/bootstrap-responsive-tabs.css">
<script type="text/javascript" src="http://vtimbuc.github.io/bootstrap-responsive-tabs/dist/js/jquery.bootstrap-responsive-tabs.min.js"></script>
<!-- Modernizr JS -->
<script src="js/modernizr-2.6.2.min.js"></script>
<!-- FOR IE9 below -->
<!--<script src="js/respond.min.js"></script>-->
</head>
<body>
<div class="gtco-loader"></div>
<div id="page">
<div class="page-inner">
<nav class="gtco-nav" role="navigation">
<div class="gtco-container">
<div class="row">
<div class="col-sm-4 col-xs-12">
<div id="gtco-logo"><a href="index.jsp">VUDA </a></div>
</div>
<div class="col-xs-8 text-right menu-1">
<ul>
<% if(session2.getAttribute("tipo").toString().contains("U")|| cookie.getValue().substring(0,1).contains("U")){ %>
<li><a href="ObrasServlet?page=1">Obras</a></li>
<li class="has-dropdown">
<a href="paquetes.jsp">Paquetes</a>
<%if(Login.idTitular != null){%>
<ul class="gtco-dropdown">
<li><a href="PaquetesActivos.jsp">Paquete Activo</a></li>
</ul>
<%}%>
</li>
<% }else if(session2.getAttribute("tipo").toString().contains("T") || cookie.getValue().substring(0,1).contains("T")){%>
<li><a href="ListaObrasServlet?page=1">Obras</a></li>
<% }else if(session2.getAttribute("tipo").toString().contains("S") || cookie.getValue().substring(0,1).contains("S")){
System.out.println("Se crearon los links");
%>
<li><a href="ListaTitularServlet?page=1">Titulares</a></li>
<li><a href="ObrasServlet?page=1">Obras</a></li>
<%}%>
<li class="has-dropdown">
<a href="#">Sedes</a>
<ul class="gtco-dropdown">
<li><a href="#">SGC</a></li>
<li><a href="#">Indecopi</a></li>
<li><a href="#">Ministerio de cultura</a></li>
<li><a href="#">MCET</a></li>
</ul>
</li>
<% if(session2.getAttribute("tipo").toString().contains("U") || cookie.getValue().substring(0,1).contains("U")){
System.out.println(cookie.getName() + " " + cookie.getValue());
%>
<li><a href="#">PreCalculador</a></li>
<% } %>
<li><a href="#">Contactenos</a></li>
<li class="btn-cta" <% if(session2.getAttribute("username")!=null || cuser != null) out.print("style='display:none;'");%>><a id="btn2" data-toggle="modal" data-target="#loginModal"><span>Usuario</span></a></li>
<li class="btn-cta" <% if(session2.getAttribute("username")!=null || cuser != null) out.print("style='display:inline;'");else out.print("style='display:none;'");%>><a href="logoutServlet"><span>Cerrar Sesion</span></a></li>
</ul>
</div>
</div>
</div>
</nav>
<div class="container" <% if(session2.getAttribute("username")!=null || cuser != null) out.print("style='display:none;'");%>>
<div id="loginModal" class="modal fade" role="dialog">
<div class="modal-dialog " id="loginModalDialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="close" ><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Iniciar Sesion</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-lg-4 col-lg-push-1 animate-box" data-animate-effect="fadeInRight">
<div class="form-wrap">
<form action="#">
<div class="row form-group">
<div class="col-md-12">
<div for="username">Nombre de Usuario o Email</div>
<input type="text" class="form-control" id="username">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label for="password">Contraseña</label>
<input type="password" class="form-control" id="password">
</div>
</div>
<div class="row form-group">
<div class="col-md-12 right">
<a href="Registrarse.jsp">Registrarse</a>
</div>
<div class="col-md-12">
<input type="submit" class="btn btn-primary" value="Login">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
首先需要检查c
是否为空,然后执行System.out.println(c.getName() + " " + c.getValue());
所以将代码更改为:
for (Cookie c : g) {
if (c != null) {
System.out.println(c.getName() + " " + c.getValue());
if (c.getName().compareTo("tipo") == 0) {
cookie.setValue(c.getValue());
}
if (c.getName().compareTo("usuario") == 0) {
cuser = c;
}
}
}