linux - 从jsp表单在centos 5中创建一个用户

标签 linux shell jsp centos5

我有一个通过 post 方法发送的表单 registration.jsp 文件,首先保存在数据库中,然后必须打开一个“command.sh”:

<%@ page import ="java.sql.*,java.io.*"%>
<%
   String user = request.getParameter("uname");    
    String pwd = request.getParameter("pass");
      Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jsp",
            "root", "");
    Statement st = con.createStatement();

    int i = st.executeUpdate("insert into members(uname, pass, regdate) values ('" + user + "','" + pwd + "', CURDATE())");

  Process p=Runtime.getRuntime().exec("./command.sh "+user+pwd);
        if (i > 0) {
              response.sendRedirect("welcome.jsp");
     } else {
        response.sendRedirect("index.jsp");
    }

我正在使用以下代码,但是当我运行它时出现错误:

Error

Files

是的,保存在数据库中。 我也不知道如何通过接收我从jsp发送的数据来创建一个Unix用户。

请帮帮我

最佳答案

尝试使用 ServletContext.getRealPath(),例如:

String fullPath = application.getRealPath("command.sh");
String[] cmd = { fullPath + " " + user + pwd };
Process p = Runtime.getRuntime().exec(cmd);

关于linux - 从jsp表单在centos 5中创建一个用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48854536/

相关文章:

jsp - jsp taglib 与包含 jsp 页面的根本区别是什么?

linux - Linux 上对 cmake 的官方 32 位支持是否已取消?

node.js - 尝试在 linux 上运行 npm run build 时,NPM 给出 ELILIFECYCLE 错误

shell - 如何获取可以删除的文件夹列表?

linux - erreur commande 剪切脚本 shell

java - 如何在现有背景图像上添加侧边菜单(导航菜单)

java - 无法在 JSP 中设置 header 。响应已经提交

linux - tshark SIP协议(protocol)显示崩溃

linux - 如何设置 cron 显示 gui 应用程序

bash - Bash 脚本中范围内的随机数