-2

I have a problem in Spring MVC. I can't run JSP as a view on server... I uploaded all libraries, but I get the following error when I run view on server:

Sep 29, 2013 10:53:22 AM org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production >environments was not found on the java.library.path: C:\long path....

[SetContextPropertiesRule]{Context} Setting property 'source' to >'org.eclipse.jst.jee.server:SpringMVC' did not find a matching property.

web.xml:

<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>Spring MVC Application</display-name>

  <servlet>
     <servlet-name>HelloWeb</servlet-name>
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
     <servlet-name>HelloWeb</servlet-name>
     <url-pattern>/</url-pattern>
     </servlet-mapping>
</web-app>

HelloWeb-servlet.xml:

<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"
  xsi:schemaLocation="
  http://www.springframework.org/schema/beans     
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <context:component-scan base-package="Controllers" />

  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
  </bean>

</beans>

As below the controller name is HelloController.java

package Controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;

 @Controller
 @RequestMapping("/hello")
 public class HelloController{

    @RequestMapping(method = RequestMethod.GET)
    public String printHello(ModelMap model) {
        model.addAttribute("message", "Hello Spring MVC Framework!");
        return "hello";
    }
 }

As below A view name is hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
         <title>Hello World</title>
   </head>
   <body>
      <h2>${message}</h2>
   </body>
 </html>
Community
  • 1
  • 1
SW Engineer
  • 67
  • 2
  • 3
  • 9
  • What problem have you faced? The pages does not load to browser? How do you return `View`s? APR library has no impact on JSP rendering, it just uses native connectors to increase perfomance. – madhead Sep 29 '13 at 08:36
  • Please show your controller. – Dirk Lachowski Sep 29 '13 at 10:11
  • I know this is silly, but where is your hello.jsp located? – blackpanther Sep 29 '13 at 10:43
  • @DirkLachowski Lachowski i added the controller and view – SW Engineer Sep 29 '13 at 10:44
  • @blackpanther hello.jsp in subfolder path = /WebContent/WEB-INF/jsp/hello.jsp – SW Engineer Sep 29 '13 at 10:48
  • @ SW Engineer According to what I'm seeing online that error should NOT be a show-stopper. What are you getting when you try and run your app? Any output at all? I created a Eclipse MVC project and copied your code into it vebatim, the result was... A running application. So by process of elimination your problem lies elsewhere. Please post the exact jars you are using. Did you verify they are in the build path? Please recheck your project directory structure. Have you tried deleting and redepoying your app in Tomcat? Also, check again closely in your Tomcat console log for other errors. – wSchmidt Sep 29 '13 at 17:19

1 Answers1

1

Most likely fix: looks like you need a <url-pattern> of /* or similar (not just /) in your <servlet-mapping> web.xml. /hello will not go to the Spring DispatcherServlet, as is.

The APR message is not significant -- it's a performance warning, and won't prevent your app from running.


WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpringMVC' did not find a matching property.

This may or may not be an issue.. See: "SetPropertiesRule" warning message when starting Tomcat from Eclipse

Does your context fail to load? Look for a final error message from Tomcat. Serious errors prevent the context loading, & the the whole webapp will not function. Try a static index.html page within the context to see if you can view it -- static pages/resources are only served if the context is running.

If the context is not loading, you will need to fix the problem that prevents it.

If the context is loading OK, then it's probably a URL/ config issue within your application.

Community
  • 1
  • 1
Thomas W
  • 13,940
  • 4
  • 58
  • 76
  • @SWEngineer -- did you fix your `` yet? You also need to let us know whether the context has loaded & is running OK, or failed. – Thomas W Sep 29 '13 at 11:01
  • i chenged and the problem i can't load page. – SW Engineer Sep 29 '13 at 11:19
  • You're not supplying enough information, which would be necessary to identify or resolve the problem. StackOverflow is not a guessing game.. more diagnosis & information are needed from your side. – Thomas W Sep 30 '13 at 04:10
  • The problem is the page can't load ...when i run the page shows me HTTP Status 404! – SW Engineer Oct 03 '13 at 07:11
  • As I said, that's not enough information. You haven't even said if your context starts up, or not! This is not the industry for you if you're lazy or can't be bother diagnosing problems. On my Tomcat, context error gives (for example) `SEVERE: Context [/jr] startup failed due to previous errors`. Diagnose the problem & post some information. As I said very clearly, **StackOverflow is not a guessing game.** – Thomas W Oct 03 '13 at 22:21