作为Jsp和Java的初学者,我正在构建一个简单的Web应用程序,用于显示从数据库到网页的数据
当我运行以下代码时,我收到以下错误 HTTP状态500 - 内部服务器错误
在网络bean和Web服务器中构建Web应用程序是Glass fish
不知道出了什么问题。继续搜索谷歌但没有运气
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
UPDATE1:
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>
NextPage.jsp上
<%--
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>
答案 0 :(得分:1)
请先尝试重新安排导入和声明,然后稍后将驱动程序加载为scriptlet:
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<% Class.forName("com.mysql.jdbc.Driver"); %>
接下来,班级重命名不合适。你班上的第一个字母应该是资本。所以将其重命名为Imaging。最好在源包中定义这个类,而不是在JSP页面内声明并使用它。
问题区域是您的PreparedStatement:
selectRetouch.setString(1, limitone);
由于您要设置限制值,因此驱动程序需要Integer值而不是String。解决此问题的方法是解决方法:
selectRetouch.setInt(1, Integer.parseInt(limitone));
要通过URL测试,请直接点击链接并传递请求参数,例如:
http://localhost:8080/yourappname/yourpage.jsp?weeknum1=12