doukuiqian9911 2014-12-10 02:05
浏览 48

使用HTML字符串输入,我可以保存该字符串并将其作为参数(java)在PHP exec()命令中传递吗?

Currently, I have a java .class file that I want to run when a button is pressed and PHP exec() command calls it.

Say I have this in a .class file:

class Test {
public static void main(String[] args) {
    String a = args[0];
    System.out.println(a);
    }
}

Now I want PHP to execute this java using the exec() function. However, this class file needs parameters. I want to feed parameters through a form and submit button.

To the visitors, upon loading the site they would see the average form + submit:

<form action="action_page.php">
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
<br><br>
<input type="submit" value="Submit">
</form>

Once they hit the submit button, I want the button to call PHP command

exec(java test username lastname)

given "username" and "lastname" is generated by the visitor.

</div>
  • 写回答

1条回答 默认 最新

  • douqu8828 2014-12-10 02:10
    关注

    First of all, add method="post" to your form:

    <form action="action_page.php" method="post">
    

    Then on submit you will be able to access the form inputs using the $_POST variable. Make sure you call escapeshellarg() on user input variables.

    $username = escapeshellarg($_POST['username']);
    $lastname = escapeshellarg($_POST['lastname']);
    

    And then you can use exec():

    exec("java test $username $lastname");
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度