Java HTTP状态500-内部服务器错误-JSP-玻璃鱼服务器

Java HTTP状态500-内部服务器错误-JSP-玻璃鱼服务器,java,jsp,netbeans,glassfish,Java,Jsp,Netbeans,Glassfish,作为Jsp和Java的初学者,我正在构建一个简单的web应用程序,它将数据从数据库显示到网页 当我运行下面的代码时,我得到以下错误HTTP状态500-内部服务器错误 在NetBeans和web服务器中构建web应用程序是玻璃鱼 不知道出了什么问题。仍在搜索谷歌,但还没有运气 type Exception report messageInternal Server Error descriptionThe server encountered an internal error that pr

作为Jsp和Java的初学者,我正在构建一个简单的web应用程序,它将数据从数据库显示到网页

当我运行下面的代码时,我得到以下错误HTTP状态500-内部服务器错误

在NetBeans和web服务器中构建web应用程序是玻璃鱼

不知道出了什么问题。仍在搜索谷歌,但还没有运气

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.NullPointerException
root cause

java.lang.NullPointerException
更新1:

Warning:   StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at org.apache.jsp.nextPage_jsp._jspService(nextPage_jsp.java:111)
    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)
Index.jsp

<%-- 
    Document   : index
    Created on : Jan 1, 2015, 7:36:04 PM
    Author     : ksathis
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Inside</title>
    </head>
    <body>
        <h1>Inside</h1>
        <form name="mainForm" action="nextPage.jsp" method="POST">
            <table border="0">
                <tbody>
                    <tr>
                        <td>DateRange</td>
                        <td><input type="radio" name="radioS" id="dateRadio" value="1" /></td>
                        <td><input type="date" name="date1" value="0" size="10" /></td>
                        <td><input type="date" name="date2" value="0" size="10" /></td>
                    </tr>
                    <tr>
                        <td>WeekNum</td>
                        <td><input type="radio" name="radioS" id="weekRadio" value="1" /></td>
                        <td><input type="text" name="weeknum1" id="weeknum1" value="0" size="10" /></td>
                    </tr>
                    <tr>
                        <td>MonthNum</td>
                        <td><input type="radio" name="radioS"  id="monthRadio" value="1" /></td>
                        <td><input type="text" name="monthnum1" value="0" size="10" /></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td><input type="reset" value="Clear" name="Clear" size="10"/><input type="submit" value="submit" name="Clear" size="10"/></td>
                    </tr>
                </tbody>
            </table>
        </form>
    </body>
</html>
<%-- 
    Document   : nextPage
    Created on : Jan 1, 2015, 7:55:59 PM
    Author     : ksathis
--%>

<%@page import="java.sql.*" %>
<% Class.forName("com.mysql.jdbc.Driver"); %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Result</title>
    </head>
    <body>
        <h1>DIS SLA RESULT FOR THE WEEK !</h1>
        <%!
            public class imaging {

                String URL = "jdbc:mysql://localhost:3306/database1";
                String USERNAME = "root";
                String PASSWORD = "password";

                Connection connection = null;
                PreparedStatement selectRetouch = null;
                ResultSet resultSet = null;

                public imaging() {
                    try {
                        connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
                        selectRetouch = connection.prepareStatement("select * from retouch limit 1 , ?");

                    } catch (SQLException e) {
                        e.printStackTrace();
                    }

                }

                public ResultSet imaging_Result(String limitone) {
                    try {
                        selectRetouch.setString(1, limitone);
                        resultSet = selectRetouch.executeQuery();

                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return resultSet;
                }
            }
        %>
        <%
            String str = new String();
            str = request.getParameter("weeknum1");
            imaging image = new imaging();
            ResultSet images = image.imaging_Result(str);
        %>
        <table border="1">
            <tbody>
                <tr>
                    <td>Retail_sku</td>
                    <td>Region</td>
                </tr>
                <% while (images.next()) {%>

                <tr>
                    <td><%= images.getString("retail_sku")%></td>
                    <td><%= images.getString("region")%></td>
                </tr>
                <% }%>
            </tbody>
        </table> 
    </body>
</html>

在…内
在…内
日期范围
周数
蒙特纳姆
Nextpage.jsp

<%-- 
    Document   : index
    Created on : Jan 1, 2015, 7:36:04 PM
    Author     : ksathis
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Inside</title>
    </head>
    <body>
        <h1>Inside</h1>
        <form name="mainForm" action="nextPage.jsp" method="POST">
            <table border="0">
                <tbody>
                    <tr>
                        <td>DateRange</td>
                        <td><input type="radio" name="radioS" id="dateRadio" value="1" /></td>
                        <td><input type="date" name="date1" value="0" size="10" /></td>
                        <td><input type="date" name="date2" value="0" size="10" /></td>
                    </tr>
                    <tr>
                        <td>WeekNum</td>
                        <td><input type="radio" name="radioS" id="weekRadio" value="1" /></td>
                        <td><input type="text" name="weeknum1" id="weeknum1" value="0" size="10" /></td>
                    </tr>
                    <tr>
                        <td>MonthNum</td>
                        <td><input type="radio" name="radioS"  id="monthRadio" value="1" /></td>
                        <td><input type="text" name="monthnum1" value="0" size="10" /></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                        <td><input type="reset" value="Clear" name="Clear" size="10"/><input type="submit" value="submit" name="Clear" size="10"/></td>
                    </tr>
                </tbody>
            </table>
        </form>
    </body>
</html>
<%-- 
    Document   : nextPage
    Created on : Jan 1, 2015, 7:55:59 PM
    Author     : ksathis
--%>

<%@page import="java.sql.*" %>
<% Class.forName("com.mysql.jdbc.Driver"); %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Result</title>
    </head>
    <body>
        <h1>DIS SLA RESULT FOR THE WEEK !</h1>
        <%!
            public class imaging {

                String URL = "jdbc:mysql://localhost:3306/database1";
                String USERNAME = "root";
                String PASSWORD = "password";

                Connection connection = null;
                PreparedStatement selectRetouch = null;
                ResultSet resultSet = null;

                public imaging() {
                    try {
                        connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
                        selectRetouch = connection.prepareStatement("select * from retouch limit 1 , ?");

                    } catch (SQLException e) {
                        e.printStackTrace();
                    }

                }

                public ResultSet imaging_Result(String limitone) {
                    try {
                        selectRetouch.setString(1, limitone);
                        resultSet = selectRetouch.executeQuery();

                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return resultSet;
                }
            }
        %>
        <%
            String str = new String();
            str = request.getParameter("weeknum1");
            imaging image = new imaging();
            ResultSet images = image.imaging_Result(str);
        %>
        <table border="1">
            <tbody>
                <tr>
                    <td>Retail_sku</td>
                    <td>Region</td>
                </tr>
                <% while (images.next()) {%>

                <tr>
                    <td><%= images.getString("retail_sku")%></td>
                    <td><%= images.getString("region")%></td>
                </tr>
                <% }%>
            </tbody>
        </table> 
    </body>
</html>

结果
本周的成绩!
零售单品
区域

请先重新安排导入和声明,然后作为脚本加载驱动程序:

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<% Class.forName("com.mysql.jdbc.Driver"); %>
因为您正在设置一个限制值,所以驱动程序需要的是一个整数值,而不是字符串。要解决此问题,这里有一个解决方法:

 selectRetouch.setInt(1, Integer.parseInt(limitone));
要通过URL对此进行测试,请直接点击链接并传递请求参数,例如:

http://localhost:8080/yourappname/yourpage.jsp?weeknum1=12

您没有发布完整的异常堆栈跟踪。在哪一行出现了更新1部分中更新的
NullPointerException
?@unwichtich请检查我的答案,我添加了更多内容。我想限制用户限制行数。是的,如果我取消注释该行,它将起作用。但我需要从用户那里获得输入,然后我必须使用sql查询。更新了我的问题(删除了limt 1,10,添加了1,?)。对不起,太好了。谢谢兄弟:)