Detecting Key Press in jsp

2019-08-10 14:21发布

I have a menu bar on a web based program that is built using jsp. Usually, my company uses java scriplets to add functionality, but I have been reading about JSTL and was wondering if there was a way to determine if two keys were pressed simultaneously using JSTL. Also, is there any general rules or conventions to be followed when revising scriplets into JSTL?

标签: java jsp jstl
1条回答
干净又极端
2楼-- · 2019-08-10 15:10

I don't think there is any way to detect key input using JSTL. As far as I know JSTL, it is a collection of these five types of tags:

Core Tags: used for accessing variables, iterating objects, and (almost) all of the standard loops and if-else statements that you would expect in a programming language.

Formatting tags: Dates, strings etc

SQL tags: Database stuff

XML tags: like core, but for xml

JSTL Functions: Functions like contains, join, split, substring etc

You can read more about it here: http://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm

Your best bet for creating a key listener, is javascript. Take a look at this post for more info: Detect multiple keys on single keypress event in jQuery

For the other part of your question, I have found particularily two answers already existing on stackoverflow, to be most helpful:
How to avoid Java code in JSP files?
How to avoid using scriptlets in my JSP page?

EDIT: As mentioned in the comments, JSTL works on the server side of a web application. user input happens on the client side, and is therefore out of scope for JSTL. Javascript is the way to go.

查看更多
登录 后发表回答