0

I'm trying to use angularjs routing to load my templates and am getting a '404 page not found error' no matter what templateurl I put down. Should I be changing my context.xml file or am I just missing a step here? Any input would be appreciated.

This is my routing config (app.js):

    app.config(function($routeProvider) {
        $routeProvider.when('/', {
            templateUrl: 'views/mainview',
            controller: 'appController'
        })
        .otherwise({
            redirectTo: '/'
        });
   });

=============================

And my Spring Controller is as follows (SampleController.java):

    @Controller
    public class SampleController {

        @RequestMapping(value="views/mainview", method=RequestMethod.GET)
        public String displayView(){
           return "views/mainview.jsp";
        }
     }

=============================

Folder structure is as Follows

  • java

    • com
      • sample
        • controller
          • SampleController.java
  • webapp

    • META-INF
    • resources
      • js
        • app.js
    • WEB-INF
      • views
        • mainview.jsp

2 Answers 2

0

templateUrl property defines which HTML template AngularJS should load and display inside the div with the ngView directive. Use templateUrl : 'mainview.html'

Sign up to request clarification or add additional context in comments.

5 Comments

So then I shouldn't worry about the Spring Controller? I've tried so many combinations of the path for templateUrl and still getting a page not found error?
Correct this @RequestMapping(value="views/mainview", metohd=RequestMethod.GET) in your code, you have written "method" as "metohd" @angularjs newbie
Try to return only "mainview" from your controller's method.
Tried that. Should I be changing web.xml? Or should it just work with my angularjs routing config?
Can't you post your all files
0

First you need to check the server where the server is serving file

for example : java/com/views/mainview.html or views/mainview.html

1 Comment

I edited the structured of my folders in the question. My app.js file is located in webapp/resources/js/app.js and my template is located in webapp/WEB-INF/view/mainview.html. Would it still just be views/mainview.html? I've tried it and still getting the same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.