Create a simple web form with the following inputs on it: Set the method to be P
ID: 3667080 • Letter: C
Question
Create a simple web form with the following inputs on it: Set the method to be POST and the action to be formProcess.php A prompt for username (text input), set both the size and maxlength attributes to 15 characters A prompt for a password (input type=password). Set the size attribute to be 15 but no limit on characters submitted. A prompt to confirm the password (input type=password). Set the size attribute to be 15 but no limit on characters submitted. A pair of radio buttons with the prompt "I agree to the terms and conditions" with the choices of yes and no. A textarea that is 6 rows and 50 columns labeled as "Enter comments here" A submit button and a reset button. Create the formProcess.php script, it should Confirm that the initial password and confirmation of the password match (are the exact same) Evaluate the strength of the password, simply re-use the restrictions and (most of) your code from Exercise 3-5. If the password is "good" tell the user, if it is not tell the user why it is not. If the user did not agree to the terms and conditions, tell them so and then exit If they did agree to the terms and conditions, count the total words entered in the textarea for comments, and count the number of times each word appeared in the comments. Then display the words and the count for each in a table, using alternating background colors on each row. You do not need to get fancy with the web design portion of this, but your page should be well formatted and visually clean. The same applies to your output generated by the formProcess.php script. Upload both your HTML file and formProcess.php script to the dropbox, and include the URL for your HTML form as a submission comment.
Explanation / Answer
import javax.servlet.http.*;
import javax.servlet.*;
import java.sql.*;
/**
* Servlet implementation class MySQLConnect
*/
public class MySQLConnect extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String user = request.getParameter("user");
String pass = request.getParameter("pass");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/javademo", "root", "");
PreparedStatement pst = conn.prepareStatement("Select user,pass from login where user=? and pass=?");
pst.setString(1, user);
pst.setString(2, pass);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
out.println("Correct login credentials");
}
else {
out.println("Incorrect login credentials");
}
}
catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
}
html>
<head>
<title>Login form</title>
</head>
<body>
<form method="post" action="MySQLConnect">
Username :<input type="text" name="user" /><br/><br/>
Password :<input type="password" name="pass" /><br/><br/>
<input type="submit" value="Login" />
</form>
</body>
</html>
<servlet>
<servlet-name>MySQLConnect</servlet-name>
<servlet-class>MySQLConnect</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MySQLConnect</servlet-name>
<url-pattern>/MySQLConnect</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.