Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the calculation of string expression in OA Credit disk system by java

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how java realizes the string expression calculation of OA credit tray system. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Scheme 1: eval function

Making qeval function in OA credit disk system is probably the first scheme that comes to mind, and it is also the simplest and most direct scheme. Let's try it out:

$a = 10

Var_dump (eval ('return $a > 5X'))

/ / output:

/ / bool (true)

Well, it fully meets our needs, because the Java expression executed by the eval function, as long as the expression in the string conforms to the Java syntax.

It should be noted, however, that the eval function can execute arbitrary Java code, which means that it is privileged, risky, and insecure. If your string expression comes from external input, be sure to do your own security check and filtering, and consider the risk. Of course, external input expressions are executed, and this function is highly deprecated.

Option 2: include temporary files

How to achieve it? Write the string expression to a temporary file, then include the temporary file, and delete the temporary file when the execution is complete.

The plan is still simple. There are some things to consider:

There will be many temporary files, there are many in a request, and the expiration and deletion of files must be taken into account.

The reading and writing of the file also involves the disk IO, so the performance must be seriously affected.

So do we still adopt this plan?

Scenario 3: assert assertion

In fact, assert can not evaluate string expressions, but it is also a guess, because it can verify whether PHP expressions are legal or not.

The following example demonstrates how to verify that a string expression is a valid PHP expression:

Try {

Assert ('a + = = 1')

} catch (Throwable $e) {

Echo $e-> getMessage (), "\ n"

}

Running result:

Failure evaluating code:

A + = 1

But there is still a problem, which is security, because arbitrary code can be executed as well as eval. Therefore, expressions of string type can no longer be executed starting with Java 7.2.Expressions of string type can no longer be executed.

On "java how to achieve OA credit tray system string expression calculation" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report