How can I display an error message in the very same JSP when a user submits a wrong input? I do not intend to throw an exception and show an error page.
相关问题
- Date with SimpleDateFormat in Java
- RegEx Max and Min length characters for a Text Box
- #{facesContext} EL expression not resolved at runt
- jsp caching tag library
- what's wrong in my URL validation Regex using
相关文章
- jsp里面的画布功能,为什么会出错?求大佬找下问题
- Angular Material Stepper causes mat-formfield to v
- JSP String formatting Truncate
- Why doesn't Django enforce my unique_together
- Forward request from servlet to jsp
- X/Html Validator in PHP
- Using CascadeMode.StopOnFirstFailure on a validato
- DDD Domain Model Complex Validation
Easiest would be to have placeholders for the validation error messages in your JSP.
The JSP
/WEB-INF/foo.jsp
:In the servlet where you submit the form to, you can use a
Map<String, String>
to get hold of the messages which are to be displayed in JSP.The Servlet
@WebServlet("foo")
:In case you create more JSP pages and servlets doing less or more the same, and start to notice yourself that this is after all a lot of repeated boilerplate code, then consider using a MVC framework instead.
See also:
I'm not quite sure what you mean by "display error message". If you have a standard error handling, then you can always check for options:
Of course, this is just the notion; preferably, you'd have your own exception class. But then again, I'm not quite sure what you're after.
I see tag "form-validation", so maybe you should just use JavaScript and client form validation? If you need validation with JSP, handle form data, and redisplay the form with an error message or accept form data, if it's correct.