Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I use switch/case logic using enums in a JSP?

843841Jul 17 2006 — edited Jul 18 2006
I inherited a JSP that uses switch / case logic based on a single
character that was picked up by a getAttribute method.
String mainInfo = (String)request.getAttribute("MAININFO");
char info = mainInfo.charAt(0);
switch(info) {
	case 'A':
		break;
	case 'B':
		break;
	...etc...
	}
The characters ('A', 'B', etc) in themselves aren't meaningful to the function of the JSP. I'd like to replace the single character with a string
that would be more meaningful.

From what I've been able to read, I could contain all the possible string
values using the enum class, but I've looked at the examples until I'm
cross-eyed, and I can't figure out how I would incorporate it into a JSP.

How & where would I define the enum class so I could essentially do this?:
String mainInfo = (String)request.getAttribute("MAININFO");
switch(mainInfo) {
	case CASEA:
		break;
	case CASEB:
		break;
	...etc...
	}
TIA.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 15 2006
Added on Jul 17 2006
1 comment
282 views