Servlet call from Tomcat throwing HTTP Status 500 - java.lang.NullPointerException - java

I am trying to call my servlet GetAttributeValueServlet from apache tomcat and this error has been shown.
The Servlet is in CloudWebServerClient.
Severe: Servlet.service() for servlet [servlet.GetAttributeValueServlet] in context with path [/CloudWebServiceClient] threw exception
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.lang.NullPointerException
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}hostname
java.lang.NullPointerException
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.client.service.WebServiceProxySoapBindingStub.getAttributeValue(WebServiceProxySoapBindingStub.java:297)
at com.client.service.WebServiceProxyProxy.getAttributeValue(WebServiceProxyProxy.java:50)
at servlet.GetAttributeValueServlet.doGet(GetAttributeValueServlet.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>CloudWebServiceServer</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<display-name>GetAttributeValueServlet</display-name>
<servlet-name>GetAttributeValueServlet</servlet-name>
<servlet-class>com.src.servlet.GetAttributeValueServlet</servlet-class>
</servlet>
<servlet>
<display-name>Apache-Axis Servlet</display-name>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GetAttributeValueServlet</servlet-name>
<url-pattern>/CloudWebServiceClient/WebContent/GetAttributeValueServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet>
<display-name>Axis Admin Servlet</display-name>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>org.apache.axis.transport.http.AdminServlet</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AdminServlet</servlet-name>
<url-pattern>/servlet/AdminServlet</url-pattern>
</servlet-mapping>
</web-app>
GetAttributeValueServlet:
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.client.service.WebServiceProxy;
import com.client.service.WebServiceProxyProxy;
/**
* Servlet implementation class GetAttributeValueServlet
*/
#WebServlet("/GetAttributeValueServlet")
public class GetAttributeValueServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public GetAttributeValueServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setHeader("Access-Control-Allow-Origin", "*");
response.setContentType("text/xml;charset=utf-8");
String EntityID=request.getParameter("entity_id");
String AttrName=request.getParameter("attrName");
//String Value=request.getParameter("value");
System.out.println(EntityID+AttrName);
WebServiceProxy wsp = new WebServiceProxyProxy();
System.out.println("Huuu"); //just to see if it is coming to this point and yes it comes to this point and after that throws exception!
String isGet = wsp.getAttributeValue(EntityID, AttrName);
System.out.println("Hagfgfg"); //it doesn't shows this value!
PrintWriter pw = response.getWriter();
pw.print(isGet);
return;
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}

Before using values you pull from request.getParameter() you should check them to see if they are null and do something if they are.
String entityID = request.getParameter("entity_id");
if(entityID==null)
{
entityID = "";
//or maybe print a message to user "Entity ID is required field" and return;
}
Or you can make sure they're not null like this:
String entityID = "" + request.getParameter("entity_id");
This would mean if what comes out of request.getParameter() was null, now it will be the String value "null" rather than null.

I resolved it.... The problem was in parameter attrName which was Null and it was because of wrong function call ;) thanx anyways

Related

Spring controller allocate exception for servlet with ArrayIndexOutOfBoundsException [duplicate]

This question already has answers here:
Failed to load ApplicationContext caused by ArrayIndexOutOfBoundsException in ClassReader
(5 answers)
Closed 5 years ago.
Hi guys i've been having trouble with one of my controllers, when I go to call it it throws an ArrayIndexOutOfBoundsException and I have no idea why. I've tried changing the configuration of web.xml and everything over and over and am getting nowhere. I get the following exception when attempting to call /categories:
SEVERE: StandardWrapper.Throwable
java.lang.ArrayIndexOutOfBoundsException: 3145
at org.springframework.asm.ClassReader.readClass(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:54)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.checkConfigurationClassCandidate(ConfigurationClassBeanDefinitionReader.java:302)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:172)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:142)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:599)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1720)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Nov 03, 2017 8:59:19 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet rest
java.lang.ArrayIndexOutOfBoundsException: 3145
at org.springframework.asm.ClassReader.readClass(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:54)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.checkConfigurationClassCandidate(ConfigurationClassBeanDefinitionReader.java:302)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:172)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:142)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:599)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1720)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
This is the FinderController class:
package uk.co.igindex.multilingualtranslation.application.rest;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import uk.co.igindex.multilingualtranslation.application.rest.response.FinderTranslationResponse;
import uk.co.igindex.multilingualtranslation.domain.Locale;
import uk.co.igindex.multilingualtranslation.eai.cache.FinderTranslationCache;
import uk.co.igindex.multilingualtranslation.eai.cache.TranslationCache;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
#Controller
#RequestMapping("/finder")
public class FinderController {
FinderTranslationCache finderCache;
TranslationCache translationCache;
#Autowired
public FinderController(FinderTranslationCache finderTranslationCache, TranslationCache translationCache) {
this.finderCache = finderTranslationCache;
this.translationCache = translationCache;
}
#RequestMapping(value = "/underlyings", method = RequestMethod.GET, headers = "content-type=application/json")
#ResponseBody
public String getUnderlyingTranslations() {
FinderTranslationResponse f = new FinderTranslationResponse();
for (Locale localeKey : finderCache.getUnderlyingTranslationKeys().keySet()) {
for (String combinedKey : finderCache.getUnderlyingTranslationKeys().get(localeKey).keySet()) {
f.addLocaleTranslation(localeKey.getValue(), finderCache.getUnderlyingTranslationKeys().get(localeKey).get(combinedKey),
translationCache.getCacheEntryFromCombinedKey(combinedKey));
}
}
return jsonify(f.returnLocaleMap());
}
#RequestMapping(value = "/contracts", method = RequestMethod.GET, headers = "content-type=application/json")
#ResponseBody
public String getContractTranslations() {
FinderTranslationResponse f = new FinderTranslationResponse();
f.addLocaleTranslation("en_GB", "translationKey", "translationValue");
f.addLocaleTranslation("en_GB", "translationKeysd", "translationValue");
f.addLocaleTranslation("en_GB", "translationKey3", "translationValue");
return jsonify(f.returnLocaleMap());
}
#RequestMapping(value = "/categories", method = RequestMethod.GET, headers = "content-type=application/json")
#ResponseBody
public String getCategoryList() {
StringBuilder sb = new StringBuilder();
for (String s : finderCache.getCategory()) {
sb.append(s + "\n");
}
return sb.toString();
}
#RequestMapping(value = "/miscellaneous", method = RequestMethod.POST, headers = "content-type=application/json")
#ResponseBody
public Map<String, String> getMiscellaneousTranslations(Set<String> words, String locale){
return new HashMap<>();
}
public String jsonify(Map map) {
JSONObject jsonObject = new JSONObject();
jsonObject.putAll(map);
return jsonObject.toString();
}
public void setTranslationCache(TranslationCache translationCache) {
this.translationCache = translationCache;
}
public void setFinderCache(FinderTranslationCache finderCache) {
this.finderCache = finderCache;
}
}
This is the web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<description>Multi-lingual Translation Web Application.</description>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:properties/multilingualtranslation/multilingualtranslation-log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:MultilingualTranslation-jdbc.xml,
classpath*:MultilingualTranslation-config.xml,
classpath*:MultilingualTranslation-service.xml,
classpath*:MultilingualTranslation-jms.sf.xml,
classpath*:MultilingualTranslation-jndi.xml
</param-value>
</context-param>
<listener>
<listener-class>uk.co.igindex.multilingualtranslation.application.listener.MultilingualTranslationsContextListener</listener-class>
</listener>
<servlet>
<servlet-name>MultilingualTranslationDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- <init-param>
<param-name>wl-dispatch-policy</param-name>
<param-value>ClientVerificationWorkManager</param-value>
</init-param>-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/rest-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--
Remoting servlet to support remote calls over HTTP (i.e. http
invoker).
-->
<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
<!--
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>-->
<servlet-mapping>
<servlet-name>MultilingualTranslationDispatcher</servlet-name>
<url-pattern>/translation</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MultilingualTranslationDispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<!-- MONITOR -->
<servlet>
<servlet-name>monitor</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/monitor-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>monitor</servlet-name>
<url-pattern>/monitor/*</url-pattern>
</servlet-mapping>
<resource-ref>
<description>Oracle DB Connection</description>
<res-ref-name>multilingualtranslationservice/jdbc/datasource/MultilingualTranslationService</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
and this is the rest-servlet.xml class
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="uk.co.igindex.multilingualtranslation.application.rest" />
<mvc:annotation-driven />
<import resource="classes/MultilingualTranslation-service.xml"/>
<bean id="finderController"
class="uk.co.igindex.multilingualtranslation.application.rest.FinderController">
</bean>
</beans>
Your problem happens here:
#RequestMapping(value = "/categories", method = RequestMethod.GET, headers = "content-type=application/json")
#ResponseBody
public String getCategoryList() {
StringBuilder sb = new StringBuilder();
for (String s : finderCache.getCategory()) {
sb.append(s + "\n");
}
return sb.toString();
}
The problem happens in your finderCache.getCategory(). where your getCategory has no items in it.
Please check with a debugger what finderCache.getCategory() has
If this isnt the problem, please post the logcat of your error.

error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver?

I am trying simple login authentication using servlets and jdbc connection to MySQL database. After executing it on tomcat server I am getting following error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.leader.prog.Validate.checkUser(Validate.java:13)
at com.leader.servlet.Login1.doPost(Login1.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
I am sharing the content of all files:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.leader.servlet.Login1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>welcome</servlet-name>
<servlet-class>com.leader.servlet.Welcome</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>welcome</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>Home.html</welcome-file>
</welcome-file-list>
</web-app>
Login1.java
package com.leader.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.leader.*;
import com.leader.prog.Validate;
#WebServlet("/Login1")
public class Login1 extends HttpServlet {
/**
* #see HttpServlet#HttpServlet()
*/
public Login1() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String user = request.getParameter("userName");
String pass = request.getParameter("password");
if(Validate.checkUser(user.toString(),pass.toString()))
{
RequestDispatcher rs = request.getRequestDispatcher("Welcome");
rs.forward(request, response);
}
else
{
out.println("Username or Password incorrect");
RequestDispatcher rs = request.getRequestDispatcher("Home.html");
rs.include(request, response);
}
}
}
validate.java
package com.leader.prog;
import java.sql.*;
public class Validate
{
public static boolean checkUser(String user,String pass)
{
boolean st =false;
try{
//loading driver
Class.forName("com.mysql.jdbc.Driver");
//creating connection with the database
Connection con=DriverManager.getConnection
("jdbc:mysql://localhost:3306/person","root","password");
PreparedStatement ps =con.prepareStatement
("select * from person where pid=? and password=?");
ps.setString(1, user);
ps.setString(2, pass);
ResultSet rs =ps.executeQuery();
st = rs.next();
}catch(Exception e)
{
e.printStackTrace();
}
return st;
}
}
Please help me to get out of this issue.
Check the availability of mysql driver is in classpath. If you are using IDE(eclipse) try to add it to build path.
You should add Mysql connector library you your project buildpath
You can download library from
http://dev.mysql.com/downloads/connector/j/5.0.html
or
http://www.java2s.com/Code/Jar/c/Downloadcommysqljdbc515jar.htm

doFilter method on java - null pointer exception on filterchain when session is invalidate

this is my java filter (doFilter method):
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
String uri = req.getRequestURI();
// context.log("Requested Resource::"+uri);
if ((!req.isRequestedSessionIdValid()
&& (uri.endsWith("Login.jsp") || uri.endsWith("LoginServlet")) ||
req.isRequestedSessionIdValid())) {
// pass the request along the filter chain
try {
filterChain.doFilter(req, res);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
res.sendRedirect("Logout");
}
} else {
res.sendRedirect("Logout");
// context.log("Unauthorized access request");
}
}
public void destroy() {
}
}
I use this filter because i need to controll if the session is valid or not;
this is useful in case of , after logout, if the back button of browser is pressed, automaticly it redirect the client on Login.jsp.
The problem is on try catch module: infact without it, when i try to press back button the JVM give me the follow error:
org.apache.jasper.JasperException: java.lang.NullPointerException
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:534)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.connection.filter.ServletFilter.doFilter(ServletFilter.java:41)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
at org.apache.jsp.Home_jsp._jspService(Home_jsp.java:155)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
... 22 more
i think that this happen because the filterchain is not present, when there are a not valid session, but how can manage this problem? i think that the "try catch" module is not a good solution.
thanks
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>LoginServlet</display-name>
<servlet>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.connection.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<display-name>Logout</display-name>
<servlet>
<display-name>Logout</display-name>
<servlet-name>Logout</servlet-name>
<servlet-class>com.connection.servlet.Logout</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Logout</servlet-name>
<url-pattern>/Logout</url-pattern>
</servlet-mapping>
<filter>
<filter-name>ServletFilter</filter-name>
<filter-class>
com.connection.filter.ServletFilter
</filter-class>
<init-param>
<param-name>avoid-urls</param-name>
<param-value>Login.jsp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ServletFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
this is logout servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setHeader("Cache-Control", "no-cache, no-store");
response.setHeader("Pragma", "no-cache");
request.getSession().invalidate();
response.sendRedirect("Login.jsp");
}

jersey NoClassDefFoundError: org/objectweb/asm/ClassVisitor exception

First time I'm trying a WebService using jersey. The below code I got from some blog.
I am getting following 500 error when I'm trying Java Web service using jersey client
javax.servlet.ServletException: Servlet.init() for servlet Jersey Root REST Service threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
com.sun.jersey.api.core.servlet.WebAppResourceConfig.init(WebAppResourceConfig.java:102)
com.sun.jersey.api.core.servlet.WebAppResourceConfig.<init>(WebAppResourceConfig.java:89)
com.sun.jersey.api.core.servlet.WebAppResourceConfig.<init>(WebAppResourceConfig.java:74)
com.sun.jersey.spi.container.servlet.WebComponent.getWebAppResourceConfig(WebComponent.java:672)
com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:415)
com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:582)
com.sun.jersey.spi.container.servlet.WebServletConfig.getDefaultResourceConfig(WebServletConfig.java:87)
com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:703)
com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:678)
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)'
Below is my web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>RestFulWeb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey Root REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Root REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>'
Here i tried adding the package also that didn't help:
Added only one jar file jersey-bundle-1.14.jar. The following is my Jersey server
package com.rest.server;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.rest.data.Hello;
// POJO, no interface no extends
// The class registers its methods for the HTTP GET request using the #GET annotation.
// Using the #Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML.
// The browser requests per default the HTML MIME type.
//Sets the path to base URL + /hello
#Path("/hello")
public class HelloWorldRest {
#GET
#Path("/{param}/")
public String getMsg(#PathParam("param") String msg) {
String output = "Jersey say : " + msg;
return output;
}
#GET
#Path("/world")
public String getFixedMsg(String msg) {
String output = "Jersey say : fixed path" + msg;
return output;
}
// This method is called if TEXT_PLAIN is request
#GET
//#Path("helloworld")
#Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
System.out.println("sayPlain");
return "Hello Jersey";
}
// This method is called if XML is request
#GET
//#Path("helloworld")
#Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
System.out.println("sayXML");
return "" + " Hello Jersey" + "";
}
// This method is called if HTML is request
#GET
//#Path("helloworld")
#Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
System.out.println("sayHTML");
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
// This method is called if JSON is request
#GET
//#Path("helloworld")
#Produces(MediaType.APPLICATION_JSON)
public Hello sayJsonHello() {
return new Hello("Hello", "Jersey");
}
#POST
#Produces(MediaType.APPLICATION_JSON)
public Hello createHello(Hello hello)
{
System.out.println("post");
return hello;
}
}'
currently I'm trying only with GET hitting the following url http://localhost:8080/RestFulWeb/hello, I am getting the 505 error.
DO i missed any jar files , but i didn't get any compile time error.
This is caused by the missing of asm.jar,
Add this dependency
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
While writing a webservice I was getting following error:
INFO: Scanning for root resource and provider classes in the packages:
com.webservice.services
Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
at com.webservice.StartWebService.startAttrService(StartWebService.java:32)
at com.webservice.StartWebService.main(StartWebService.java:20)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.ClassVisitor
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 5 more
I included asm.jar in my java project and error gone.
I was following steps from restful-web-services-first-application-mock-service-using-pure-java

HTTP 400 and 500 error messages

when I run my application, I'm having a HTTP error:
HTTP Status 404 - /ProjectName/
This is the URL of my project:
localhost:8080/Initiation1/
When I type this string to the address bar:
localhost:8080/Initiation1/CarteIdentite
, I'm having this HTTP 500 error message:
javax.servlet.ServletException: Error instantiating servlet class ca.web.CarteIdentite
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.ClassNotFoundException: ca.web.CarteIdentite
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
This is my servlet code:
package ca.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
/**
* Servlet implementation class CarteIdentite
*/
#WebServlet("/CarteIdentite")
public class CarteIdentite extends HttpServlet
{
// paramètres d’instance
private String defaultNom = null;
private String defaultAge = null;
private String defaultCourriel = null;
//init
public void init()
{
// on récupère les paramètres d’initialisation de la servlet
ServletConfig config = getServletConfig();
defaultNom = config.getInitParameter("defaultNom");
if(defaultNom==null)
{
defaultNom="XXXXXXXXXXXXXXXX";
}
defaultAge = config.getInitParameter("defaultAge");
if(defaultAge==null)
{
defaultAge="AAA";
}
defaultCourriel = config.getInitParameter("defaultCourriel");
if(defaultCourriel==null)
{
defaultCourriel="XXXXXX#XXXXXXXX.XX";
}
}
//GET
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException
{
// on récupère les paramètres du formulaire
String nom = request.getParameter("txtNom");
if (nom == null)
{
nom = defaultNom;
}
String age = request.getParameter("txtAge");
if (age == null)
{
age = defaultAge;
}
String courriel = request.getParameter("txtCourriel");
if (courriel == null)
{
courriel = defaultCourriel;
}
// on affiche le formulaire
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println
(
"<html>"+
"<head>"+
"<title>Carte d’identité</title>"+
"</head>"+
"<body>"+
"<center>"+
"<h2>Carte d’identité</h2>"+
"<form action=’’ method=’post’>"+
"<table>"+
"<tr>"+
"<td>Nom:</td>"+
"<td><input name=’txtNom’ value=’"+nom+"’ type=’text’ size=’30’></td>"+
"</tr>"+
"<tr>"+
"<td>Age:</td>"+
"<td><input name=’txtAge’ value=’"+ age +"’ type=’text’ size=’3’></td>"+
"</tr>"+
"<tr>"+
"<td>Courriel:</td>"+
"<td><input name=’txtCourriel’ value=’"+courriel+"’ type=’text’ size=’30’></td>"+
"</tr>"+
"</table>"+
"<table>"+
"<tr>"+
"<td><input type=’submit’ value=’Envoyer’></td>"+
"<td><input type=’reset’ value=’Effacer’></td>"+
"</tr>"+
"</table>"+
"</form>"+
"</center>"+
"</body>"+
"</html>"
);
}
/**
* #param request la requête HTTP du client
* #param response la réponse HTTP qu’on va construire
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
//on passe la main au GET
doGet(request, response);
}
}
This is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app SYSTEM "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>CarteIdentite</servlet-name>
<servlet-class>ca.web.CarteIdentite</servlet-class>
<init-param>
<param-name>defaultNom</param-name>
<param-value>inconnu</param-value>
</init-param>
<init-param>
<param-name>defaultAge</param-name>
<param-value>XXX</param-value>
</init-param>
<init-param>
<param-name>defaultCourriel</param-name>
<param-value>inconnu</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>CarteIdentite</servlet-name>
<url-pattern>/CarteIdentite</url-pattern>
</servlet-mapping>
</web-app>
Here is my project structure:
Maybe Eclipse isn't treating src as a source folder. Try right clicking on it and choosing Build Path -> Use as source folder.
Check if the class ca.web.CarteIdentite has compiled correctly and made way into the WAR of your project (under WEB-INF/classes). If not, check/correct the project buildpath settings.

Categories