This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Http Status 404 - Servlet DataAccessServlet is currently unavailable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Http Status 404 - Servlet DataAccessServlet is currently unavailable " Watch "Http Status 404 - Servlet DataAccessServlet is currently unavailable " New topic
Author

Http Status 404 - Servlet DataAccessServlet is currently unavailable

Ramesh kangamuthu
Ranch Hand

Joined: Mar 13, 2007
Posts: 79
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Ramesh kangamuthu
Ranch Hand

Joined: Mar 13, 2007
Posts: 79
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Ramesh kangamuthu
Ranch Hand

Joined: Mar 13, 2007
Posts: 79
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.
 
 
subject: Http Status 404 - Servlet DataAccessServlet is currently unavailable
 
Similar Threads
Tomcat manager problems
Unable to Run Servlet
Servlet Chaining
Spring - MySql Connectivity Error
Connection pooling issue in Apache 6.0