I am going to pass error message from inside the Java class to JSP and this error message is written in .properties
file.
I am using action class method addActionError(result)
to display that error message but it is displaying the message as error.register.bademail
in JSP. This is not my written message.
Java class:
package com.uttarainfo.s2;
public class Model {
public List<String> register(RegBean bean) {
if(bean.getEmail().equals("bond@gmail.com"))
return "error.register.bademail"; i want to return this key
else
return "success";
}
}
Action class:
if(result.equals(SUCCESS))
return SUCCESS;
else
{
addActionError(result);
return "failure";
}
This is JSP code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Register</h1>
<s:form action="register" method="post" enctype="multipart/form-data">
<s:textfield key="bean.uname"/>
<s:textfield key="bean.email"/>
<s:password key="bean.pwd"/>
<s:password key="bean.rpwd"/>
<s:file key="bean.pic"/>
<s:submit/>
<s:actionerror/>
</s:form>
</body>
</html>