0

我从另一个调用此代码的 jsp 代码获取 datetime1 ,datetime2,moteid 作为输入。这工作正常,脚本 1.sh 工作正常。当我运行此代码时,它显示 HTTP 状态 500 错误

<%@page import="java.io.BufferedReader"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.File"%>
<%@page import="java.util.Map"%>
<%@page import="com.sixpanview.fileReader"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <%  
                String id = request.getParameter("moteid");
                String[] temp = id.split(":");
                String moteid = temp[0];
                String datetime1 = temp[1];     
                String datetime2 = temp[2];
                String moteId = temp[3];
                    String sh = "sh";
                    String rep = "/root/NetBeansProjects/JavaApplication/web/1.sh";
                    String cpid = "\"" + moteid + "\"";
                    String mm = datetime1;
                    String nn = datetime2;
                    String kk = moteId;


                    String[] cmdarr = new String[]{sh, rep, moteid, mm, nn, kk};

                    File file=new File("/root/NetBeansProjects/JavaApplication/web");
                    ProcessBuilder pb = new ProcessBuilder(cmdarr);

                    pb.directory(file);
                    Process p = pb.start();
                    p.waitFor();

                           %>



       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                <title>JSP Page</title>
            </head>
            <body>
                <iframe src="report.pdf" width="100%" height="700px"/>

            </body>
        </html>

它的显示

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /pdf1jsp.jsp at line 23

20:     <head>
21:         <%  
22:             String id = request.getParameter("moteid");
23:             String[] temp = id.split(":");
24:             String moteid = temp[0];
25:             String datetime1 = temp[1];     
26:             String datetime2 = temp[2];


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
    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:717)

root cause

java.lang.NullPointerException
    org.apache.jsp.pdf1jsp_jsp._jspService(pdf1jsp_jsp.java:80)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    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:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.
4

1 回答 1

0

22: 字符串 id = request.getParameter("moteid");

这里 id 为空,这就是在第 23 行抛出 NPE 的原因:

String[] temp = id.split(":");

于 2012-10-13T12:21:25.663 回答