• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Java Based Spring Configuration with Angular JS client - control not transferred (@requestMapping)

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to Spring Annotations and Angular JS. I am building an application using:-

1. Spring 4 Java based Configuration (Annotations)
2. Angular JS
3. eclipse IDE
4. I am not using maven or anything else for building the project.

I've created the following files:-

1. web.xml

-with SpringAppConfig.java defined in context param as contextConfigLocation
-with SpringConfig.java defined in init-param under DispatcherServlet definition as contextConfigLocation

2. SpringAppConfig.java //Code below


3. SpringConfig.java // Code below


4. FrontController.java



Now the problems are
1. When I run my application the index.html(created using angularjs) declared in welcome-file-list of web.xml is getting opened. But when I click on submit entering some details. it is not forwarding to either controller or to the path I defined in @requestMapping. I've got stuck and I don't know what exactly I am missing.

2. I am not getting the context path in my html page which I could easily by EL or JSTL in JSP. What should I do to get the context path considering I am not going to use JSP at all.


I am new to both Spring annotations and Angularjs. Please help me to make this application work. Also please reply in case any other information is needed to answer this question. Thanks in advance.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swapnil Dubey wrote:
1. When I run my application the index.html(created using angularjs) declared in welcome-file-list of web.xml is getting opened. But when I click on submit entering some details. it is not forwarding to either controller or to the path I defined in @requestMapping. I've got stuck and I don't know what exactly I am missing.


where is the control submitting? what do you see in the URL? show us your index.html page also

Swapnil Dubey wrote:
2. I am not getting the context path in my html page which I could easily by EL or JSTL in JSP. What should I do to get the context path considering I am not going to use JSP at all.


You are expecting JSTL/EL to work in HTML (.html extension) file?
 
Nakshatra Dubey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Prasad Krishnegowda wrote:

where is the control submitting? what do you see in the URL? show us your index.html page also



Below is controller.js (angularJs) which is called from index.html while submitting it using ng-submit. and it returns 'Unexpected server error.' I checked the status is 404.








Prasad Krishnegowda wrote:

You are expecting JSTL/EL to work in HTML (.html extension) file?



I know JSTL/EL can't work on HTML pages. I tried using $location of angularjs to get context path. but $location is also coming as null, while loading of the page.

I tried including project name before the URL, but it also return 404.
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what happens when you directly invoke, http://<host>:<port>/<contextpath>/frontController.htm/sampleMethod directly from the browser, do you see a 404 page? and what happens when you invoke, http://<host>:<port>/<contextpath>/frontController.htm?

I know JSTL/EL can't work on HTML pages. I tried using $location of angularjs to get context path. but $location is also coming as null, while loading of the page.


First, location should be accessed using ${location} not $location, again are you expecting this to work in .js extension file. If yes, sorry, it wont work, you need to embed the script in JSP file itself, or pass this value a parameter to JS function from JSP file.
 
Nakshatra Dubey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Prasad Krishnegowda wrote:

what happens when you directly invoke, http://<host>:<port>/<contextpath>/frontController.htm/sampleMethod directly from the browser, do you see a 404 page? and what happens when you invoke, http://<host>:<port>/<contextpath>/frontController.htm?



It gives HTTP Status 404, The requested resource is not available for both the urls.




Prasad Krishnegowda wrote:

First, location should be accessed using ${location} not $location, again are you expecting this to work in .js extension file. If yes, sorry, it wont work, you need to embed the script in JSP file itself, or pass this value a parameter to JS function from JSP file.



I think I couldn't make it clear earlier. Actually, I am not using extension files I am using extension file. And the js file I am using is of angularjs which allows me to use its $location attribute, which according to angularjs API reference gives the URL path
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It gives HTTP Status 404, The requested resource is not available for both the urls.


Ok, so the problem is with Spring configuration only. What is url-pattern you have configured for Spring DispatcherServlet in web.xml?
 
Nakshatra Dubey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
*.htm
 
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swapnil Dubey,

Please post your web.xml file.
 
Nakshatra Dubey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It has been resolved.
since the mistake I made was critical to configuration.

I was trying for angularjs and spring. Being a newbie to angularjs I didn't know to configure a Spring Application with angularjs which in core is pure HTML, providing is not sufficient. I've to configure my DispatcherSelvlet to parse static content too. So, I reinvented the wheel and tried the same project by converting all files to files and it worked. That's when I found where I went wrong.

Thanks a ton for your replies.
 
Always look on the bright side of life. At least this ad is really tiny:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic