wood burning stoves
The moose likes Other Application Frameworks and the fly likes How display errormessage from model on jsp page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "How display errormessage from model on jsp page?" Watch "How display errormessage from model on jsp page?" New topic

How display errormessage from model on jsp page?

Cheng-Hao Hsu

Joined: Feb 23, 2009
Posts: 3
I plan write a login example with Netbean6.5 and Spring2.5.

I write a jsp page(login.jsp) to save user's account and password into command object,
then send to controller (LoginAction.java).

On LoginAction.java I return a model to login.jsp in order to display error message,
but I dont know how to display it on jsp page.

I read API, errors.getModel() is a model with hashmap class,
and I add two error messages by rejectValue(),
but What express language should I write on login.jsp,
then I can display the error messages on login.jsp?

This example is from book,but it's can't run,
so I fix the code.
Has anyone can tell me what should I do?

Document : login
Created on : 2009/4/3, 上午 09:55:47
Author : Administrator

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>


<spring:bind path="command.*">


<form name="loginform" method="post" action="validator.do">

<spring:bind path="command">

名稱<input type="text" name="account" value="${command.account}"/>

密碼<input type="password" name="password" value="${command.password}"/>


<input type="submit" value="送出"/>

<%--<vld:validate validationName="loginform" page="0"/>--%>


package edu.chenghao.internal.common.web.controller;

import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import edu.chenghao.internal.common.web.form.LoginForm;
import java.util.List;

public class LoginAction extends SimpleFormController
public LoginAction()

protected ModelAndView onSubmit(Object arg0, BindException errors) throws Exception

LoginForm loginForm=(LoginForm)arg0;

if(loginForm.getAccount().equals("test") && loginForm.getPassword().equals("1234"))
HashMap hm=new HashMap();
ArrayList al=new ArrayList();
return new ModelAndView(this.getSuccessView(),hm);

List list = errors.getAllErrors();
for( int i=0; i<list.size(); i++){
System.out.println( "第"+i+"個"+ list.get(i) );


return new ModelAndView(this.getFormView(),errors.getModel());
//return new ModelAndView(this.getFormView(),this.getCommandName(),loginvo);



Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Well, I can't help you much with how you are doing it there. As I believe that is how you might have done it before Spring 2.5 Maybe Spring 2.0 or before.

But for me, I create a login page exactly like I would with straight JSP using the j_ properties in the login page.

Then in Spring, I would configure Spring Security and set a <login-page> to your page.

In your web.xml you use FORM for security, all this is from the Servlet/JSP spec, and it follows it to a tee.

I hope that helps move you in the right direction.

Good Luck


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Cheng-Hao Hsu

Joined: Feb 23, 2009
Posts: 3
Thanks your advise.

I need a job, so I learn Spring just because many companies project use it.
But you are right that use Servlet/jsp are basic and suitable.

Maybe I should learn the basic skills again.

I agree. Here's the link: http://aspose.com/file-tools
subject: How display errormessage from model on jsp page?
It's not a secret anymore!