i keep getting that error on line 139. i need help please
Code:
* RegLoginServletHW3.java
*
* Created on October 17, 2007, 10:29 PM
*/
package ITIS5166;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.util.regex.*;
/**
*
* @author Administrator
* @version
*/
public class RegLoginServletHW3 extends HttpServlet {
private Hashtable users;//Info = new Hashtable();
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String username = "";
String password = "";
String passwordConfirm = "";
String usernameError = "";
String passwordError = "";
String passwordConfError = "";
if (users == null) {
users = new Hashtable();
}
HttpSession session = request.getSession();
String sessionUser = (String) session.getAttribute("user");
if (sessionUser != null){
session.invalidate();
} else {
username = (String) request.getParameter("user");
password = (String) request.getParameter("password");
passwordConfirm = (String) request.getParameter("confpass");
if (username == null && password == null && passwordConfirm == null) {
//the first time the page has been display
}
else if ( username == null || username.length() == 0) {
usernameError = "<tr class=\"content error\"><td colspan=\"2\"> Error: Please Enter a username</td></tr>\n";
} else if (password == null || password.length() ==0) {
passwordError = "<tr class><td colspan=2> Error: Please enter a password</td></tr>\n";
} else {
username = HTMLFilter(username);
if (users.containsKey(username)) {
String storedPassword = (String) users.get(username);
if (storedPassword.equals(password)) {
session.setAttribute("user", username);
response.sendRedirect("CatSerlvetHW3");
} else {
if (passwordConfirm !=null && passwordConfirm.length() > 0) {
usernameError = "<tr><td colspan=\"2\">Error: username already in use</td></tr>\n";
} else {
passwordError = "<tr><td colspan=\"2\">Error: Incorrect password</td></tr>\n";
}
}
} else {
if (passwordConfirm == null || ! password.equals(passwordConfirm)) {
passwordConfError = "<tr><td colspan=\"2\">Error: Passwords do not match</td></tr>\n";
} else {
session.setAttribute("user", username);
users.put(username,password);
response.sendRedirect("CatServletHW3");
}
}
}
}
if (username == null) {username = "";}
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
String title = "Login/Register";
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<form action= \"\" method=\"post\">\n" +
"<table border=\"1\">\n" +
"<tr><td colspan=\"2\"> Login/Register\n" +
"Account Information</td></tr>\n" +
usernameError +
"<tr><td> Request Username:</td>\n" +
"<td><input type=\"text\"\n" +
"name=\"user\" value=\"" + username + "\"/> </td></tr>\n"+
passwordError+
"<tr><td> Password:</td>\n" +
"<td><input type =\"password\"\n"+
"name=\"pass\" /></td></tr> \n" +
"<tr><td colspan\"2\"> For New Account ,\n" +
"Confirm Password</td><tr>\n" +
"passwordConfError +" +
"<tr><td>Password:</td>\n" +
"name=\"confpass\" /> </td></tr>\n" +
"<tr><td=\"2\">\n" +
"<input type=\"submit\"\n" +
"value=\"Submit\" />\n" +
"<input type=\"reset\"\n" +
"value=\"Reset\" /></td></tr>\n" +
"</table>\n" +
"</form> \n " +
"</body> \n" +
"</html> \n");
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
public static String HTMLFilter(String input){
String regex[] = {"&","<",">","\""};
String replace[] = {"&", "<", ">", """};
Matcher m;
String newString = "";
String s = input;
for (int i = 0; 1 < 4; i++) {
m = Pattern.compile(regex[i]).matcher(s);
newString = (m.find() ? m.replaceAll(replace[i]) : s);
s = newString;
}
return newString;
//} else {
// return input;
//}
}
}
Comment