0

I tried to print the message inside my hello.jsp file . I included the necessary jstl library files but it is printing ${message} instead of Welcome to the hello page.My code for controller and hello.jsp are as follows :-

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;


/**
 * Created by CAN14 on 6/14/2016.
 */
@Controller
public class HelloController{

    @RequestMapping(value="/hello", method= RequestMethod.GET)
    public ModelAndView handleRequest() throws Exception{
        ModelAndView model= new ModelAndView("hello");
        model.addObject("message","Welcome to the hello page");

        return model;
    }

}

hello.jsp

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:out value="${messsage}" />

The web.xml file is as follows:-

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
    <servlet>
        <servlet-name>helloworld</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>helloworld</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

The helloworld-servlet.xml is as follows:-

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.abhishek" annotation-config="true"/>

    <!--<bean name="/hello.ds" class="com.abhishek.HelloController" />-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >

        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>

    </bean>
</beans>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Abhishek
  • 19
  • 1
  • 6

0 Answers0