I'm planning to use spring ModelMap. And also like to specify the view name explicitly.
Do you think it's a good idea ? so that i can use the controller ?
How can I specify a view name with ModelMap? If possible give a small implementation.
Refer spring Web MVC tutorial
You will get spring Web MVC simple example from here
Related
I got task unfortunately from work to create page using spring mvc, but i never work with that. I have to do that web app with restricted specifications which are following:
JSP cannot contain javascript, java, jstl only spring mvc tag's, but it's not everything. Controller must containt vaiable's only inside methods, all methods can return only String or void, so I'm unable to use #ModelAttribute, ModelMap, Model to move data from one view to another.
Is it possible to create page with following rules? I dont realy know how beans work in Spring MVC, but it seems that it will doesnt work without it.
I am new to Spring and JSF,and I want to integrate JSF for the front end, and use Spring controller. Can Anyone give me a explanation or an example how this can be done?. Basically what I want is a form submission (which will create a Business object and feed it to the database) and navigate using controllers.
The required xml files ? and its element?
A Basic form( ex: Like a User registration )
Spring class with #Controller, and #RequestMapping etc.
I just want to know how the form submission works and the flow of that.
If you want to integrate Spring with JSF you don't need to use #Controller and #RequestMapping, those are for SpringMVC. JSF itself has navigation mechanism use that.
If you need example check Integrate Spring into JSF 2
I have followed the Spring example Serving Mobile Web Content with Spring MVC and got it working.
Now I would like to replace greeting.html with a simple static page (and replace Thymeleaf with a simpler view handler).
What is the easiest approach in this particular case?
I am new to Java, the probable solutions in web use web.xml, whereas this example does not use web.xml and it does not seem to be the recommended approach in Spring Boot documentation either. So, use #EnableAutoConfiguration with some overriding? How?
All you have to do is put the static HTML file in a place where Spring Boot will automatically look for static resources. This part of the documentation provides all the details.
So for example you can place your greeting.html under /src/main/resources/static/ and you will be able to access it at http://localhost:8080/greeting.html (that's if you have not configured a different port of the root path of the servlet context)
I'm developing an application in Spring which has numerous methods in the controller, and are mapped to various URL using #RequestMapping.
Some of these methods (and hence url) are accessible to some user roles, and not to others. Can I create annotations, and annotate these methods so that only privileged users have access to right methods, while not to the others?
Thanks in advance.
I am not sure if creating new annotations is what you really need. You could probably use Spring Security and its annotations. Please take a look here to see if it is what you are looking for.
You can use Spring Security and its annotations, restrict access to some methods. This Blog post show some features of annotations used with Spring Security 3.
Have a look at this question and answer, to see how you build your own annotations on top of spring security.
See also the documentation of Spring Security 3.1, Chapter Expression-Based Access Control.
I'm developing a web application using Spring MVC 3.0 and looking for a ready-made solution, if any, or a "best practices" reference for a url/action mapping and routing system that can achieve the following:
REST-friendly controller / method name to view mapping. The current mapping implementation translates the request to a view name, which may be problematic when using several parameters and is incompatible with REST urls
A service that accepts the name of a controller, a method and arguments values and renders the URL that's represented by them
Integration with Spring Security that can allow me to check for a given URL whether the current user is allowed to access it, so that I can decide whether or not to render a URL
A menuing system based on the above that can define menues composed of these actions and render them to page
Basically what I need is the ability to define URLs in one centralized place, so that changing a URL (during development; I'm aware of the don't-change-live-urls idea :) ) does not mean looking up and changing that URL in a zillion pages.
Any directions to such an existing solution / tutorial / guide would be great.
Thanjs
This is a feature I really miss in Spring MVC.
That's why I created the springmcv-router project, basically a port of PlayFramework's Router implementation in Spring MVC (HandlerMapping + HandlerAdapter).
I'm heavily using it in several real-world projects and the Router implementation itself is reliable.
Try using Spring Roo. It utilizes many best practices for spring MVC, and it has a scaffolding feature that automatically maintains a menu, jsp's and all the CRUD methods of a controller.
Setting up Spring Security with Roo is as simple as typing "security setup".
Hope this is helpful.