<html>
<head>
<title>generator</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="generator" method="GET">
Product: <input type="text" name="product"><br>
ActiveClientsCount: <input type="text" name="numUser"><br>
ActiveOtpCount: <input type="text" name="numUtp"><br>
Licesee: <input type="text" name="licesee"><br>
Data: <input type="text" name="data"><br>
Certificated period: <input type ="text" name="certPeriod"><br>
License: <input type="text" name="license"><br>
Password: <input type="password" name="pass"><br>
<input type="submit" value="Generate">
</form>
</body>
</html>
@WebServlet(
description = "generator servlet",
urlPatterns = { "/generator" })
public class generator extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, Exception {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String pr = request.getParameter("product");
String clientsCount = request.getParameter("numUser");
String otpCount = request.getParameter("numOtp");
String lices = request.getParameter("licesee");
String Date = request.getParameter("date");
String certPeriod = request.getParameter("certPeriod");
String pass = request.getParameter("pass");
String lic = request.getParameter("license");
String outFile = "C:/temp/asd.lic";
String keyFile = "C:/keys/lic/lic.aks";
ArrayList<Long> snlist = new ArrayList<Long>();
for (int i = 0; i < 10; i++) {
snlist.add(Long.parseLong(pr));
snlist.add(Long.parseLong(clientsCount));
snlist.add(Long.parseLong(otpCount));
snlist.add(Long.parseLong(lices));
snlist.add(Long.parseLong(Date));
snlist.add(Long.parseLong(certPeriod));
snlist.add(Long.parseLong(outFile));
snlist.add(Long.parseLong(keyFile));
snlist.add(Long.parseLong(pass));
snlist.add(Long.parseLong(lic));
}
Properties props = new Properties();
props.put("ActiveOtpCount", otpCount);
props.put("ActiveClientsCount", clientsCount);
props.put("Licensee", lices);
props.put("LicenseExpired", Date);
props.put("CertificatesPeriod", new Long(certPeriod));
LicenseGenerator.init();
KeyStore ks = KeyStore.getInstance("AKS", AkSigProv.PROV_NAME);
ks.load(new FileInputStream(keyFile), pass.toCharArray());
String a = ks.aliases().nextElement();
PrivateKey pk = (PrivateKey) ks.getKey(a, pass.toCharArray());
X509Certificate cert = (X509Certificate) ks.getCertificate(a);
out.println("<h1>" + new String(Base64.encode(cert.getEncoded())) + "</h1>");
String x = LicenseGenerator.generateLicense(pr, snlist, props, cert, pk);
try (FileOutputStream fos = new FileOutputStream(outFile)) {
fos.write(x.getBytes());
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (Exception ex) {
Logger.getLogger(generator.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (Exception ex) {
Logger.getLogger(generator.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
Я принимаю данные с html и беру ключ отсюда (C:/keys/lic/lic.aks), потом генерирую и записываю в файл, который должен находиться по адресу (C:/temp/asd.lic).
Нажимаю кнопку, но он не создает файл. В чем может быть проблема?