benk-master-flash
asked on
STRUTS HELP -- cannot resolve symbol variable MESSAGES_KEY
IN ATTEMPTING TO COMPILE THE CODE BELOW THE FOLLOWING ERROR IS GENERATED PREVENTING THE SUCCESSFUL DEPLOYMENT OF THE WEBAPP
"cannot resolve symbol variable MESSAGES_KEY"
the following is the offending line of code and whole class
MessageResources resources = (MessageResources)req.getA ttribute(A ctionMappi ng.MESSAGE S_KEY);
entire class below -->
package com.oreilly.struts.banking .form;
import javax.servlet.http.HttpSer vletReques t;
import org.apache.struts.action.A ction;
import org.apache.struts.action.A ctionError ;
import org.apache.struts.action.A ctionError s;
import org.apache.struts.action.A ctionForm;
import org.apache.struts.action.A ctionMappi ng;
import org.apache.struts.util.Mes sageResour ces;
/**
* This ActionForm is used by the online banking appliation to validate
* that the user has entered an accessNumber and a pinNumber. If one or
* both of the fields are empty when validate is called by the
* ActionServlet, error messages are created.
*/
public class LoginForm extends ActionForm {
// The user's private id number
private String pinNumber;
// The user's access number
private String accessNumber;
public LoginForm() {
super();
resetFields();
}
/**
* Called by the framework to validate the user has entered the
* accessNumber and pin fields.
*/
public ActionErrors validate(ActionMapping mapping, HttpServletRequest req ){
ActionErrors errors = new ActionErrors();
// Get access to the message resources for this application
// There's not an easy way to access the resources from an ActionForm
MessageResources resources = (MessageResources)req.getA ttribute(A ctionMappi ng.MESSAGE S_KEY);
// Check and see if the access number is missing
if(accessNumber == null || accessNumber.length() == 0) {
String accessNumberLabel = resources.getMessage( "label.accessnumber" );
ActionError newError =
new ActionError("global.error. login.requ iredfield" , accessNumberLabel );
errors.add(ActionErrors.GL OBAL_ERROR , newError);
}
// Check and see if the pin number is missing
if(pinNumber == null || pinNumber.length() == 0) {
String pinNumberLabel = resources.getMessage( "label.pinnumber" );
ActionError newError =
new ActionError("global.error. login.requ iredfield" , pinNumberLabel );
errors.add(ActionErrors.GL OBAL_ERROR , newError);
}
// Return the ActionErrors, in any.
return errors;
}
/**
* Called by the framework to reset the fields back to their default values.
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// Clear out the access number and pin number fields
resetFields();
}
/**
* Reset the fields back to their defaults.
*/
protected void resetFields() {
this.accessNumber = "";
this.pinNumber = "";
}
public void setAccessNumber(String nbr) {
this.accessNumber = nbr;
}
public String getAccessNumber() {
return this.accessNumber;
}
public String getPinNumber() {
return this.pinNumber;
}
public void setPinNumber(String nbr) {
this.pinNumber = nbr;
}
}
"cannot resolve symbol variable MESSAGES_KEY"
the following is the offending line of code and whole class
MessageResources resources = (MessageResources)req.getA
entire class below -->
package com.oreilly.struts.banking
import javax.servlet.http.HttpSer
import org.apache.struts.action.A
import org.apache.struts.action.A
import org.apache.struts.action.A
import org.apache.struts.action.A
import org.apache.struts.action.A
import org.apache.struts.util.Mes
/**
* This ActionForm is used by the online banking appliation to validate
* that the user has entered an accessNumber and a pinNumber. If one or
* both of the fields are empty when validate is called by the
* ActionServlet, error messages are created.
*/
public class LoginForm extends ActionForm {
// The user's private id number
private String pinNumber;
// The user's access number
private String accessNumber;
public LoginForm() {
super();
resetFields();
}
/**
* Called by the framework to validate the user has entered the
* accessNumber and pin fields.
*/
public ActionErrors validate(ActionMapping mapping, HttpServletRequest req ){
ActionErrors errors = new ActionErrors();
// Get access to the message resources for this application
// There's not an easy way to access the resources from an ActionForm
MessageResources resources = (MessageResources)req.getA
// Check and see if the access number is missing
if(accessNumber == null || accessNumber.length() == 0) {
String accessNumberLabel = resources.getMessage( "label.accessnumber" );
ActionError newError =
new ActionError("global.error.
errors.add(ActionErrors.GL
}
// Check and see if the pin number is missing
if(pinNumber == null || pinNumber.length() == 0) {
String pinNumberLabel = resources.getMessage( "label.pinnumber" );
ActionError newError =
new ActionError("global.error.
errors.add(ActionErrors.GL
}
// Return the ActionErrors, in any.
return errors;
}
/**
* Called by the framework to reset the fields back to their default values.
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// Clear out the access number and pin number fields
resetFields();
}
/**
* Reset the fields back to their defaults.
*/
protected void resetFields() {
this.accessNumber = "";
this.pinNumber = "";
}
public void setAccessNumber(String nbr) {
this.accessNumber = nbr;
}
public String getAccessNumber() {
return this.accessNumber;
}
public String getPinNumber() {
return this.pinNumber;
}
public void setPinNumber(String nbr) {
this.pinNumber = nbr;
}
}
ASKER
actually i meant Action.MESSAGES_KEY
using the "" around Action.MESSAGES_KEY allows it to compile.
MessageResources resources = (MessageResources)req.getA ttribute(" Action.MES SAGES_KEY" );
still can't install, but i think i should be able to fix it. if not i'll post another comment...
using the "" around Action.MESSAGES_KEY allows it to compile.
MessageResources resources = (MessageResources)req.getA
still can't install, but i think i should be able to fix it. if not i'll post another comment...
ASKER
SPOKE TOO SOON
compile generates these errors when putting Action.MESSAGES_KEY in quotes
C:\dev\banking\src\com\ore illy\strut s\banking\ form\Login Form.java: 5: warning: org.apache.struts.action.A ctionError in org.apache.struts.action has been deprecated
import org.apache.struts.action.A ctionError ;
^
C:\dev\banking\src\com\ore illy\strut s\banking\ form\Login Form.java: 42: warning: org.apache.struts.action.A ctionError in org.apache.struts.action has been deprecated
ActionError newError =
^
C:\dev\banking\src\com\ore illy\strut s\banking\ form\Login Form.java: 43: warning: org.apache.struts.action.A ctionError in org.apache.struts.action has been deprecated
new ActionError("global.error. login.requ iredfield" , accessNumberLabel );
^
C:\dev\banking\src\com\ore illy\strut s\banking\ form\Login Form.java: 44: warning: GLOBAL_ERROR in org.apache.struts.action.A ctionError s has been deprecated
errors.add(ActionErrors.GL OBAL_ERROR , newError);
^
C:\dev\banking\src\com\ore illy\strut s\banking\ form\Login Form.java: 44: warning: add(java.lang.String,org.a pache.stru ts.action. ActionErro r) in org.apache.struts.action.A ctionError s has been deprecated
errors.add(ActionErrors.GL OBAL_ERROR , newError);
^
C:\dev\banking\src\com\ore illy\strut s\banking\ form\Login Form.java: 50: warning: org.apache.struts.action.A ctionError in org.apache.struts.action has been deprecated
ActionError newError =
^
C:\dev\banking\src\com\ore illy\strut s\banking\ form\Login Form.java: 51: warning: org.apache.struts.action.A ctionError in org.apache.struts.action has been deprecated
new ActionError("global.error. login.requ iredfield" , pinNumberLabel );
^
C:\dev\banking\src\com\ore illy\strut s\banking\ form\Login Form.java: 52: warning: GLOBAL_ERROR in org.apache.struts.action.A ctionError s has been deprecated
errors.add(ActionErrors.GL OBAL_ERROR , newError);
^
C:\dev\banking\src\com\ore illy\strut s\banking\ form\Login Form.java: 52: warning: add(java.lang.String,org.a pache.stru ts.action. ActionErro r) in org.apache.struts.action.A ctionError s has been deprecated
errors.add(ActionErrors.GL OBAL_ERROR , newError);
^
9 warnings
compile generates these errors when putting Action.MESSAGES_KEY in quotes
C:\dev\banking\src\com\ore
import org.apache.struts.action.A
^
C:\dev\banking\src\com\ore
ActionError newError =
^
C:\dev\banking\src\com\ore
new ActionError("global.error.
^
C:\dev\banking\src\com\ore
errors.add(ActionErrors.GL
^
C:\dev\banking\src\com\ore
errors.add(ActionErrors.GL
^
C:\dev\banking\src\com\ore
ActionError newError =
^
C:\dev\banking\src\com\ore
new ActionError("global.error.
^
C:\dev\banking\src\com\ore
errors.add(ActionErrors.GL
^
C:\dev\banking\src\com\ore
errors.add(ActionErrors.GL
^
9 warnings
ASKER
BUILD FAILED
C:\dev\banking\build.xml:3 43: FAIL - Encountered exception java.lang.NoClassDefFoundE rror: javax/servlet/http/HttpSer vlet
now also getting this error
C:\dev\banking\build.xml:3
now also getting this error
>>Encountered exception java.lang.NoClassDefFoundE rror: javax/servlet/http/HttpSer vlet
Make sure servlet.jar is in your classpath
Make sure servlet.jar is in your classpath
You should use ActionMessage instead of ActionError
With Struts 1.2.4, you can find MESSAGES_KEY in org.apache.struts.Globals class, and ActionError is deprecated, use ActionMessage instead.
and replace ActionError.GLOBAL_ERROR by ActionMessages.GLOBAL_MESS AGE
ASKER
I am having a lot of problems making the changes b/c i am new to struts. could somebody post the correctly modified code so I can test. I would be glad to award points to all who have helped.
replacement to org.apache.struts.Globals. MESSAGES_K EY set me on the right path, the other replacements are causing problems for me now.
replacement to org.apache.struts.Globals.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
lilan-arnaud --- thanks
that seemed to work, it compiles and installs, but now the only problem is this SERVER(500) error message. I will find a way to award more points if you can get the app running for me. FYI it is the banking app from Oreilly's Programming Jakarta Struts 2nd Ed.
Type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperEx ception: Failed to load or instantiate TagExtraInfo class: org.apache.struts.taglib.b ean.Cookie Tei
org.apache.jasper.compiler .DefaultEr rorHandler .jspError( DefaultErr orHandler. java:50)
org.apache.jasper.compiler .ErrorDisp atcher.dis patch(Erro rDispatche r.java:411 )
org.apache.jasper.compiler .ErrorDisp atcher.jsp Error(Erro rDispatche r.java:283 )
org.apache.jasper.compiler .TagLibrar yInfoImpl. createTagI nfo(TagLib raryInfoIm pl.java:42 2)
org.apache.jasper.compiler .TagLibrar yInfoImpl. parseTLD(T agLibraryI nfoImpl.ja va:248)
org.apache.jasper.compiler .TagLibrar yInfoImpl. <init>(Tag LibraryInf oImpl.java :162)
org.apache.jasper.compiler .Parser.pa rseTaglibD irective(P arser.java :418)
org.apache.jasper.compiler .Parser.pa rseDirecti ve(Parser. java:483)
org.apache.jasper.compiler .Parser.pa rseElement s(Parser.j ava:1539)
org.apache.jasper.compiler .Parser.pa rse(Parser .java:126)
org.apache.jasper.compiler .ParserCon troller.do Parse(Pars erControll er.java:22 0)
org.apache.jasper.compiler .ParserCon troller.pa rse(Parser Controller .java:101)
org.apache.jasper.compiler .Compiler. generateJa va(Compile r.java:203 )
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:470)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:451)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:439)
org.apache.jasper.JspCompi lationCont ext.compil e(JspCompi lationCont ext.java:5 11)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:2 95)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:292)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:236)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
root cause
java.lang.ClassNotFoundExc eption: org.apache.struts.taglib.b ean.Cookie Tei
org.apache.catalina.loader .WebappCla ssLoader.l oadClass(W ebappClass Loader.jav a:1340)
org.apache.catalina.loader .WebappCla ssLoader.l oadClass(W ebappClass Loader.jav a:1189)
org.apache.jasper.compiler .TagLibrar yInfoImpl. createTagI nfo(TagLib raryInfoIm pl.java:41 9)
org.apache.jasper.compiler .TagLibrar yInfoImpl. parseTLD(T agLibraryI nfoImpl.ja va:248)
org.apache.jasper.compiler .TagLibrar yInfoImpl. <init>(Tag LibraryInf oImpl.java :162)
org.apache.jasper.compiler .Parser.pa rseTaglibD irective(P arser.java :418)
org.apache.jasper.compiler .Parser.pa rseDirecti ve(Parser. java:483)
org.apache.jasper.compiler .Parser.pa rseElement s(Parser.j ava:1539)
org.apache.jasper.compiler .Parser.pa rse(Parser .java:126)
org.apache.jasper.compiler .ParserCon troller.do Parse(Pars erControll er.java:22 0)
org.apache.jasper.compiler .ParserCon troller.pa rse(Parser Controller .java:101)
org.apache.jasper.compiler .Compiler. generateJa va(Compile r.java:203 )
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:470)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:451)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:439)
org.apache.jasper.JspCompi lationCont ext.compil e(JspCompi lationCont ext.java:5 11)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:2 95)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:292)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:236)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
Apache Tomcat/5.0.28
that seemed to work, it compiles and installs, but now the only problem is this SERVER(500) error message. I will find a way to award more points if you can get the app running for me. FYI it is the banking app from Oreilly's Programming Jakarta Struts 2nd Ed.
Type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperEx
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.JspCompi
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
root cause
java.lang.ClassNotFoundExc
org.apache.catalina.loader
org.apache.catalina.loader
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.JspCompi
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
Apache Tomcat/5.0.28
- Did you add struts.jar and all required jars into your WEB-INF/lib directory ?
- Did you add *.tld into WEB-INF directory ?
- Did you install 2 versions of struts into your app server ?
- Did you add *.tld into WEB-INF directory ?
- Did you install 2 versions of struts into your app server ?
MessageResources resources = (MessageResources)req.getA
since there's no such field in ActionMapping:
http://struts.apache.org/api/org/apache/struts/action/ActionMapping.html