javascript - Response jsp is not being displayed spring mvc -
i trying write 1 simple spring-mvc+angularjs application. , facing problem whenever clicking on go home "in gotohome " being printed resultant home.jsp not being displayed. not sure whether viewresolver class or giving wrong path. please me out. in advance. below files.
web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 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_3_0.xsd" > <servlet> <servlet-name>myflexconn-web</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/myflexconn-web-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>myflexconn-web</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> myflexconn-web-servlet.xml
<mvc:annotation-driven/> <context:annotation-config/> <!-- view resolver jsp --> <bean id = "viewresolver" class="org.springframework.web.servlet.view.urlbasedviewresolver"> <property name = "viewclass" value = "org.springframework.web.servlet.view.jstlview"/> <property name = "prefix" value = "/"/> <property name = "suffix" value = ".jsp"/> </bean> <mvc:resources location="/includes/" mapping="/includes/**"/> <context:component-scan base-package="com.att.flexconn.*"/> <!-- configure plugin json request , response in method handler --> <bean class = "org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter"> <property name = "messageconverters"> <list> <ref bean = "jsonmessageconverter"/> </list> </property> </bean> <!-- configure bean convert json pojo , vice versa --> <bean id = "jsonmessageconverter" class = "org.springframework.http.converter.json.mappingjackson2httpmessageconverter"/> index.jsp
<html> <head> <title>my index page</title> <script type = "text/javascript" src = "includes/js/angular.min.js"></script> <script type = "text/javascript" src="includes/js/ng/controller/index-controller.js"></script> </head> <body> <div ng-app="myflexconnapp"> <h1>my flexconn app</h1> <form ng-controller = "indexcontroller"> <input type = "button" value = "go home" ng-click = "showhome()"/> </form> </div> </body> </html> **index-controller.js** var myflexconnapp = angular.module("myflexconnapp",[]); myflexconnapp.controller("indexcontroller",["$scope","$http",function($scope,$http){ $scope.showhome=function(){ var url = "index/home"; $http.get(url); }; }]); indexcontroller.java
import org.springframework.context.annotation.lazy; import org.springframework.stereotype.controller; import org.springframework.ui.modelmap; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.web.bind.annotation.responsebody; import org.springframework.web.servlet.modelandview; @controller public class indexcontroller { @requestmapping(value = "/index/home",method = requestmethod.get) public string gotohome(){ system.out.println("in gotohome"); return "home"; } } home.jsp
<html> <head> <script type = "text/javascript" src = "includes/js/angular.min.js"></script> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>my home page</title> </head> <body> <div ng-app="myflexconnapp"> <h1>welcome flexconn home</h1> </div> </body> </html> ps:- deploying in tomcat 7

Comments
Post a Comment