这是我的Java代码:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%!
String fName = "";
String lName = "";
String gender = "";
String uOutput = "";
String uOutput2 = "";
String uOutput3 = "";
%>
<%
int i;
Cookie[] cookies = request.getCookies();
for (i=0; i < cookies.length; i++){
if (cookies[i].getName().equals("firstname")){
fName = cookies[i].getValue();
}
}
if (!fName.equals("")){
uOutput = "Hello " + fName;
}else{
fName = request.getParameter("fName");
lName = request.getParameter("lName");
gender = request.getParameter("gender");
if (gender == null){
response.sendRedirect("form.html");
}else if(gender.equals("Male")){
uOutput = "Hello mr " + lName;
}else if (gender.equals("Female")){
uOutput = "Hello miss " + lName;
}
uOutput2 = "May i call you "+fName+" ?";
uOutput3 = "<input type='submit' name='YES' value='YES' /><input type='submit' name='NO' value='NO' />";
if (request.getParameter("YES")!=null){
Cookie firstname = new Cookie("firstname",fName);
Cookie lastname = new Cookie("lastname",lName);
Cookie ugender = new Cookie("gender",gender);
response.addCookie(firstname);
response.addCookie(lastname);
response.addCookie(ugender);
}
if (request.getParameter("NO")!=null){
}
}
%>
这是HTML:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form method="POST" action="welcome.jsp?fName=<%=fName%>&lName=<%=lName%>&gender=<%=gender%>">
<h1><%= uOutput %></h1>
<h2><%= uOutput2 %></h2>
<%= uOutput3 %>
</form>
</body>
</html>
浏览器给出Glassfish服务器500内部错误,我找不到错误, 我尝试了所有的东西,但它似乎没有帮助,有时其工作正常的奇怪的事情。
这是错误:
例外
org.apache.jasper.JasperException:java.lang.NullPointerException
根本原因
显示java.lang.NullPointerException
任何人都可以帮忙吗?
完整的堆栈跟踪:
Warning: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java:58)
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:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
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:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
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:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
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:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)