Answer the question
In order to leave comments, you need to log in
Why does submit happen?
Page:
<!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>
<p id="message" >Enter your information</p>
<div id="CenterBlock">
<form method="post">
<label class="labeler">NickName</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" onsubmit="return ValidMail()" />
</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 = 'Адрес эл. почты введен правильно!';
else output = 'Адрес электронной почты введен неправильно!';
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);
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