我是J2EE新手,使用tomcat和eclipse構建示例項目。雖然index.html的負荷正常,但是當我提交頁面(或者撥打電話與Servlet),我在下面的異常收到從tomcat調用servlet拋出HTTP狀態500 java.lang.NullPointerException
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
java.util.concurrent.ConcurrentHashMap.putVal(Unknown Source)
java.util.concurrent.ConcurrentHashMap.putIfAbsent(Unknown Source)
java.lang.ClassLoader.getClassLoadingLock(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1641)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
以下是我創建
1)的index.html
文件<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="SelectCoffee.do">
select coffee
<select name="taste" size="1">
<option value="dark">dark</option>
<option value="latte">latte</option>
<option value="cold">cold</option>
<option value="chocolate">chocolate</option>
</select>
<input type="submit">
</form>
</body>
2)的web.xml
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>For Coffee</servlet-name>
<sevlet-class>com.example.web.CoffeeSelect</sevlet-class>
</servlet>
<servlet-mapping>
<servlet-name>For Coffee</servlet-name>
<url-pattern>/SelectCoffee.do</url-pattern>
</servlet-mapping>
</web-app>
3)CoffeeSelect.java
package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class CoffeeSelect extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException,ServletException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Cofee Advice");
String c= "mine : " + request.getParameter("taste");
out.println("<br>Got taste = "+c);
}}
也讓我知道,如果需要別的。請幫助,因爲這可以讓我工作:(
這沒有區別,你可以在url-pattern的使用您的自定義名稱 – 2014-10-29 05:43:23