Spring/JSTL - problem

1

Robie tutorial z oficjalnej strony Springa i od rana borykam sie z dosc irytujacym problemem. Staram sie robic wszystko po kolei tak samo jak na stronie ale np odnosnie bibliotek springa to ani w spring 2.5 ani w spring 3.1 nie ma common-libs.jar poradzilam sobie z tym pobralam z innej strony i wszystko smigalo. Doszlam do 2 czesci gdzie do gry wchodzi jstl i po dodaniu jstl-1.2.jar (potem jeszcze standard.jar ale podobno przy tej wersji jstl to nie potrzebne) i wprowadzeniu kodu to raz ze mam wrazenie ze po prostu tego jstla nie wykrywa( a mam pliki w katalogu WEB-INF/lib tez ) a dwa ze mi nie dziala jak w tomcacie uruchamiam. Wyswietlam odpowiednio pliki jakie mam i blad.

/WEB-INF/jsp/header.jsp

<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

/WEB-INF/jsp/hello.jsp

<%@ include file ="/WEB-INF/jsp/header.jsp" %>

<html>
	<head><title>HELLO : Spring Application</title></head>
	<body>
		<h1>Hello - Spring Application</h1>
		<p>Hey! jest teraz: <c:out value="${now}"/></p>
	</body>
</html>

/WEB-INF/index.jsp

<%@ include file = "/WEB-INF/jsp/header.jsp" %>
<%@ page isELIgnored="false" %>
<%-- Redirected because we can't set the welcome page to a virtual URL. --%>

<c:redirect url="/hello.htm"/>

/WEB-INF

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	 version="2.5">
    <servlet>
	    <servlet-name>springapp</servlet-name>
	    <servlet-class>jstl.demo.JSTLDemoServlet</servlet-class>
	    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	    <load-on-startup>1</load-on-startup>
	</servlet>

  	<servlet-mapping>
    	<servlet-name>springapp</servlet-name>
    	<url-pattern>*.htm</url-pattern>
  	</servlet-mapping>
    
	<welcome-file-list>
	    <welcome-file>
	        index.jsp
	    </welcome-file>
	</welcome-file-list>
    
</web-app>

/WEB-INF/springapp-servlet

<?xml version="1.0" encoding="UTF-8"?>




<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/beans/spring-beans-3.5.xsd">

  <!-- the application context definition for the springapp DispatcherServlet -->

  <bean name="/hello.htm" class="springapp.web.HelloController"/>

</beans>

A blad jaki mi sie obecnie pokazuje to:

 
Exception report

message Servlet.init() for servlet springapp threw exception

description The server encountered an internal error (Servlet.init() for servlet springapp threw exception) that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet springapp threw exception
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
	org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	java.lang.Thread.run(Thread.java:679)
root cause

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [springapp.web.HelloController] for bean with name '/hello.htm' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]; nested exception is java.lang.ClassNotFoundException: springapp.web.HelloController
	org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1262)
	org.springframework.beans.factory.support.Abstr................................

Dałoby rade się jakoś pomóc:)?

0

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [springapp.web.HelloController] for bean with name '/hello.htm'

gdzie masz stworzona klasę Controller ? bo nie widzę zebyś miała ją tu wypisane.
EDIT: Ew sciagnij sobie STS i w opcja nowego projektu jest Spring Template Project i cała podstawowa konfiguracja projektu jest automatycznie ustawiana - zaoszczedza to duzo czasu i kłopotu.

0

HelloController:

package SpringApp.web;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.IOException;

import java.util.Date;		//odpowiedzialne za czas


public class HelloController implements Controller {

    protected final Log logger = LogFactory.getLog(getClass());

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    	
    	String now = (new Date()).toString();
        logger.info("Returning hello view with "+ now);

        return new ModelAndView("WEB-INF/src/hello.jsp", "now", now);
    }


}

Ogolnie struktura katalogów wydaje mi sie ze jest ok:

+SpringApp
+src
+SpringApp,web
-HelloController.java
-JRE System Library
-junit-4.10.jar
-servlet-api.jar
+Spring //wszystkie jary ze springa
-commons-logging-1.1.1.jar
+JSTL
-jstl-1.2.jar
standard-1.1.2.jar
+test
-HelloControllerTests.java
+war
+WEB-INF
+classes
-HelloController.class
-HelloControllerTests.class
+jsp
-header.jsp
-hello.jsp
+lib
-...biblioteki z gory czyli Spring JSTL commonsloging i servlet-api
-springapp-servler.xml
-web.xml
-index.jsp
-build.properties
-build.xml

Ogolnie to wydaje mi sie ze cos z tym jstlem jest nie tak(albo zla biblioteka albo cos w kodzie namieszalam) a nie z bibliotekami springa ale glowy nie dam:P

0

Aj taki glupi błąd! Okazało się że w springapp-servlet odniesienie do HelloController było złe. tzn on się znajduje w paczce SpringApp.web a ja wpisałam springapp.web -

1 użytkowników online, w tym zalogowanych: 0, gości: 1