Answer the question
In order to leave comments, you need to log in
Why does the user write to the server?
There is a simple registration form
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Create User</title>
<link rel="stylesheet" href="create.css">
<script type="text/javascript" src="create.js"></script>
</head>
<body>
<h1>Create Account</h1>
<div id="CenterBlock">
<form method="post" onsubmit="return ValidMail()">
<p id="message" >Enter your information</p>
<label class="labeler">Username</label><br>
<input class="inputer" name="nickname"/><br><br>
<label class="labeler">Password</label><br>
<input class="inputer" name="password" type="password" /><br><br>
<label class="labeler">Email</label><br>
<input class="inputer" id="email" name="email" /><br><br>
<input class="button" type="submit" value="Save"/>
</form>
</div>
</body>
</html>
function ValidMail() {
var re = /^[\w-\.][email protected][\w-]+\.[a-z]{2,4}$/i;
var myMail = document.getElementById('email').value;
var valid = re.test(myMail);
if (valid) output = 'E-mail address writed correct!';
else output = 'E-mail address writed incorrect!';
document.getElementById('message').innerHTML = output;
return valid;
}
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author User
*/
@WebServlet("/create")
public class CreateServlet extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
getServletContext().getRequestDispatcher("/create.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String nickname = request.getParameter("nickname");
String email = request.getParameter("email");
String password = request.getParameter("password");
Users users = new Users(nickname,email, password);
UsersDB.insert(users);
getServletContext().getRequestDispatcher("/create.jsp").forward(request, response);
//response.sendRedirect(/*request.getContextPath()+*/"/index.html");
}
catch(Exception ex) {
getServletContext().getRequestDispatcher("/create.jsp").forward(request, response);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question