I am using Spring MVC to create my web application, and I have validated the standards found in the URL There is a question about What is the best way for a user to detect invalid parameters and display errors?
Suppose I have a "see user profile" page based on the user ID parameter specified in the profile URL displayed. I can go to the following address to see the user's profile with ID 92:
I created a profile controller
Object that will do the following:
- Receive
id
fromrequest
object - <
UserProfile
Create aModelAndView
This works fine if the user enters a valid ID number My UserProfile
object has been loaded and is fully displayed using JSP . But what if a user ID sends -30294
to my page? If the ID is invalid, then my data access layer will return a null
object, but I want to show a friendly error message to the user. Checking the best solution for a null
user profile
object in the JSP code?
Since I'm new to Spring, I'm not sure. I can be used with the validator
sections with the FormController
object, if this is any help.
If the DAO cancels, return ModelAndView to just an error page
Example:
User Profile Profile = User ProfileDOO.FindUserProfileBYD (User ID); If (profile == faucet) {Return new model and view ("error", "message", "invalid user id"); } And {// process accordingly. }
In Spring 2.5 Distribution, check the jpetstore application in the samples directory. Find an org.springframework.samples.jpetstore.web.spring.SignonController for a simple example with an application.
Comments
Post a Comment