• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Http Status 404 - Servlet DataAccessServlet is currently unavailable

 
Ramesh kangamuthu
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I created a simple spring application using a simple database with a table on which I do read,store,delete and update operations.When I click the submit button in the welcome page there is an error that shows,

Http Status 404- Servlet DataAccessServlet is currently unavailable. I use Eclipse IDE. Help me to solve this problem. I provided my code.

web.xml

?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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">
<display-name>
RoseIndiaPersistence</display-name>
<servlet>
<description>
</description>
<display-name>
DataAccessServlet</display-name>
<servlet-name>DataAccessServlet</servlet-name>
<servlet-class>
persistence.DataAccessServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DataAccessServlet</servlet-name>
<url-pattern>/connectDataSource</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>DataAccessForm.jsp</welcome-file>
</welcome-file-list>
</web-app>



DataAccessServlet.java


package persistence;

import java.io.*;
import java.util.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import org.springframework.beans.factory.*;
import org.springframework.beans.factory.xml.*;
import org.springframework.core.io.*;
import org.springframework.jdbc.core.*;
import org.springframework.jdbc.datasource.*;
import org.springframework.jdbc.object.*;
import org.springframework.jdbc.support.*;

/**
* Servlet implementation class for Servlet: DataAccessServlet
*
*/
public class DataAccessServlet extends javax.servlet.http.HttpServlet implements
javax.servlet.Servlet {
/*
* (non-Java-doc)
*
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public DataAccessServlet() {
super();
}

/*
* (non-Java-doc)
*
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
* HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

/*
* (non-Java-doc)
*
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
* HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub
try
{
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
String name = request.getParameter("name");
String place = request.getParameter("place");
String criteriainfo = request.getParameter("criteriainfo");
String operation = request.getParameter("operation");
System.out.println("Wait");
BeanFactory factory=new XmlBeanFactory(new FileSystemResource("config/dataconfig.xml"));
DataSourceConnection dataSourceConnection=(DataSourceConnection)factory.getBean("DataSourceConnection");
DataSource dataSource=dataSourceConnection.connectToDataSource();
if(operation.equals("add"))
{
JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
jdbcTemplate.execute("insert into dataaccess values('"+name+"','"+place+"')");
System.out.println("Record was added");
}
else if(operation.equals("delete"))
{
JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
jdbcTemplate.execute("delete from dataaccess where name='"+name+"'");
System.out.println("Record was deleted");
}
else if(operation.equals("find"))
{
List list;
JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
list=jdbcTemplate.queryForList("select * from dataaccess where name='"+name+"'");
Iterator iterator=list.iterator();
while(iterator.hasNext())
{
Object object=iterator.next();
System.out.println(object.toString());
}
System.out.println("Records were retrieved");
}
else if(operation.equals("update"))
{
if(criteriainfo.equals("name"))
{
JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
jdbcTemplate.execute("update dataaccess set dataaccess.place='"+place+"'+ where name='"+name+"'");
System.out.println("Record was updated");
}
else if(criteriainfo.equals("place"))
{
JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
jdbcTemplate.execute("update dataaccess set dataaccess.name='"+name+"'+ where place='"+place+"'");
System.out.println("Record was updated");
}
}
}
catch (Exception ex)
{
ex.printStackTrace();
}

}
}

And also It shows the error

NoClassDefinitionFoundError org/springframework/core/io/Resource

I provided all the spring jars including spring.jar along with commons-logging.jar
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the root of the problem is probably NoClassDefinitionFoundError org/springframework/core/io/Resource and so the container just stops initializing everything in web.xml so your DataAccessServlet isn't even initialized in the container which is why you get a 404.

I'm moving this to the Application Frameworks forum as this is about Spring and not servlets.
 
Ramesh kangamuthu
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,

I used FileSystemResource class to get application configuration file and put it as an argument to the XmlBeanFactory class to create BeanFactory.

I used two ways

one is assigning the FileSystemResource constructor to the type Resource

Resource resource=new FileSystemResource("config/dataconfig.xml")
BeanFactory factory=new XmlBeanFactory(resource)

other is directly assigning the FileSystemResource constructor with xml file as an argument to the XmlBeanFactory class.

BeanFactory factory=new XmlBeanFactory(new
FileSystemResource("config/dataconfig.xml"))


Both produced the above mentioned NoClassDefFoundError. Even I provided the spring.jar file that includes the org.springframework.core.io.Resource, tomcat shows the mentioned error.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even I provided the spring.jar file that includes the org.springframework.core.io.Resource, tomcat shows the mentioned error.

Where did you put it ? And in Eclipse, don't forget to explicitly put it in the project's classpath.
 
Ramesh kangamuthu
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe,

I included the spring.jar file in the classpath by choosing properties popup option of the project,have selected the java build path option and clicked the Add external jars button to add the spring.jar file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic