我正在尝试编写一个可以通过调用某个类的成员函数来打印的 HTML 代码,但我总是收到以下错误
HTTP Status 500 - java.lang.NullPointerException
--------------------------------------------------------------------------------
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:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
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:728)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96)
root cause
java.lang.NullPointerException
com.ly.bogha.oneworld.Pagemarkup.eBirth(Pagemarkup.java:59)
org.apache.jsp.eHealth_jsp._jspService(eHealth_jsp.java:107)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.
我的课是这个
package com.ly.bogha.oneworld;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import com.opensymphony.xwork2.ActionSupport;
public class Pagemarkup extends ActionSupport implements ServletResponseAware, ServletRequestAware {
protected HttpServletResponse mServletResponse;
protected HttpServletRequest mServletRequest;
public Pagemarkup() {
}
public void setHeader() throws IOException {
}
public void setBody() {
}
public void setFooter() {
}
@Override
public void setServletRequest(HttpServletRequest servletRequest) {
this.mServletRequest = servletRequest;
}
@Override
public void setServletResponse(HttpServletResponse servletResponse) {
this.mServletResponse = servletResponse;
}
public void eBirth() throws IOException{
mServletResponse.setContentType("text/html");
PrintWriter out = mServletResponse.getWriter();
out.print("<table><tr><td>ebirth</td></tr></table>");
}
}
我正在调用的 JSP 文件就是这个
<%@page import="com.ly.bogha.oneworld.Pagemarkup"%>
<%@ page language="java" contentType="text/html; charset=windows-1256"
pageEncoding="windows-1256"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=windows-1256">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="header.html"></jsp:include>
<%
Cookie[] cookies = request.getCookies();
int ii = 0;
boolean found = false;
String[] error = { "Authirization required to Access the Page, Please login." };
for (int i = 0; i < cookies.length; i++) {
if (cookies[i].getName().equals("nid")) {
found = true;
ii = i;
}
}
if (found == true) {
%>
<jsp:include page="ehealth.html"></jsp:include>
<%
if (request.getParameter("s") != null) {
Pagemarkup ebirth = new Pagemarkup();
int submenu = Integer.parseInt(request.getParameter("s"));
switch (submenu) {
case 1:
ebirth.eBirth();
break;
case 2:
break;
case 3:
break;
}
}
} else {
response.sendRedirect("login.jsp?msg=" + error[0]);
}
%>
</body>
当我的程序在 JSP 文件中执行以下代码时出现错误
ebirth.eBirth();