I have a form which sends by post method registration.jsp file, first saved in the database and then must open a "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");
}
I am using the following code, but when I run it I get an error:
Yes save in the database. I also do not know how to create a Unix user by receiving the data I sent from the jsp.
Please Help Me
Try using ServletContext.getRealPath()
, for example:
String fullPath = application.getRealPath("command.sh");
String[] cmd = { fullPath + " " + user + pwd };
Process p = Runtime.getRuntime().exec(cmd);