gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:11:17 25 4
gpt4 key购买 nike

我有一个通过 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com