473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

unreachable statement

24
i keep getting that error on line 139. i need help please


Expand|Select|Wrap|Line Numbers
  1.  * RegLoginServletHW3.java
  2.  *
  3.  * Created on October 17, 2007, 10:29 PM
  4.  */
  5.  
  6. package ITIS5166;
  7.  
  8. import java.io.*;
  9. import java.net.*;
  10.  
  11. import javax.servlet.*;
  12. import javax.servlet.http.*;
  13. import java.util.*;
  14. import java.util.regex.*;
  15. /**
  16.  *
  17.  * @author Administrator
  18.  * @version
  19.  */
  20. public class RegLoginServletHW3 extends HttpServlet {
  21.  
  22.     private Hashtable users;//Info = new Hashtable();
  23.  
  24.     protected void doGet(HttpServletRequest request,
  25.                       HttpServletResponse response)
  26.         throws ServletException,  IOException {
  27.  
  28.         String username = "";
  29.         String password = "";
  30.         String passwordConfirm = "";
  31.  
  32.         String usernameError = "";
  33.         String passwordError = "";
  34.         String passwordConfError = "";
  35.  
  36.         if (users == null) {
  37.             users = new Hashtable();
  38.         }
  39.  
  40.      HttpSession session = request.getSession(); 
  41.      String sessionUser = (String) session.getAttribute("user");
  42.      if (sessionUser != null){
  43.          session.invalidate();
  44.      } else {
  45.        username = (String) request.getParameter("user");
  46.        password = (String) request.getParameter("password");
  47.        passwordConfirm = (String) request.getParameter("confpass");
  48.  
  49.        if (username == null && password == null && passwordConfirm == null) {
  50.            //the first time the page has been display
  51.        }
  52.        else if ( username == null || username.length() == 0) {
  53.            usernameError = "<tr class=\"content error\"><td colspan=\"2\"> Error: Please Enter a username</td></tr>\n";
  54.        } else if (password == null || password.length() ==0) {
  55.            passwordError = "<tr class><td colspan=2> Error: Please enter a password</td></tr>\n";
  56.        } else {
  57.            username = HTMLFilter(username);
  58.            if (users.containsKey(username)) {
  59.                String storedPassword = (String) users.get(username);
  60.                if (storedPassword.equals(password)) {
  61.                    session.setAttribute("user", username);
  62.                    response.sendRedirect("CatSerlvetHW3");
  63.                    } else { 
  64.                    if (passwordConfirm !=null && passwordConfirm.length() > 0) {
  65.                        usernameError = "<tr><td colspan=\"2\">Error: username already in use</td></tr>\n";
  66.                        } else { 
  67.                        passwordError = "<tr><td colspan=\"2\">Error: Incorrect password</td></tr>\n";
  68.  
  69.                        }
  70.                    }
  71.            } else {
  72.                if  (passwordConfirm == null || ! password.equals(passwordConfirm)) {
  73.                    passwordConfError = "<tr><td colspan=\"2\">Error: Passwords do not match</td></tr>\n";
  74.                } else {
  75.                    session.setAttribute("user", username);
  76.                    users.put(username,password);
  77.                    response.sendRedirect("CatServletHW3");
  78.                       }  
  79.                    }
  80.               }
  81.           }
  82.      if (username == null) {username = "";}
  83.         response.setContentType("text/html; charset=UTF-8");
  84.         PrintWriter out = response.getWriter();
  85.         String  title = "Login/Register";
  86.         String docType =
  87.         "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
  88.         "Transitional//EN\">\n";
  89.         out.println(docType +
  90.        "<HTML>\n" +
  91.         "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
  92.         "<BODY BGCOLOR=\"#FDF5E6\">\n" +
  93.         "<form action= \"\" method=\"post\">\n" +
  94.         "<table border=\"1\">\n" +
  95.         "<tr><td colspan=\"2\"> Login/Register\n" +
  96.         "Account Information</td></tr>\n" +
  97.         usernameError +
  98.         "<tr><td> Request Username:</td>\n" +
  99.                 "<td><input type=\"text\"\n" +
  100.                 "name=\"user\" value=\"" + username + "\"/> </td></tr>\n"+
  101.                 passwordError+
  102.                 "<tr><td> Password:</td>\n" +
  103.                 "<td><input type =\"password\"\n"+
  104.                 "name=\"pass\" /></td></tr> \n" +
  105.                 "<tr><td colspan\"2\"> For New Account ,\n" +
  106.                 "Confirm Password</td><tr>\n" +
  107.                 "passwordConfError +" +
  108.                 "<tr><td>Password:</td>\n" +
  109.                 "name=\"confpass\" /> </td></tr>\n" +
  110.                 "<tr><td=\"2\">\n" +
  111.                 "<input type=\"submit\"\n" +
  112.                 "value=\"Submit\" />\n" +
  113.                 "<input type=\"reset\"\n" +
  114.                 "value=\"Reset\" /></td></tr>\n" +
  115.                 "</table>\n" +
  116.                 "</form> \n " +
  117.                 "</body> \n" +
  118.                 "</html> \n");
  119.     }
  120.  
  121.      protected void doPost(HttpServletRequest request,
  122.                  HttpServletResponse response)
  123.         throws ServletException, IOException {
  124.          doGet(request, response);
  125.         } 
  126.         public static String HTMLFilter(String input){
  127.             String regex[] = {"&","<",">","\""};
  128.             String replace[] = {"&amp;", "&lt;", "&gt;", "&quot;"};
  129.             Matcher m;
  130.             String newString = "";
  131.             String s = input;
  132.             for (int i = 0; 1 < 4; i++) {
  133.                 m = Pattern.compile(regex[i]).matcher(s);
  134.                 newString = (m.find() ? m.replaceAll(replace[i]) : s);
  135.                 s = newString;
  136.             }
  137.  
  138.             return newString;
  139.         //} else {
  140.         //   return input;
  141.        //} 
  142.         }
  143.         }   
  144.  
Oct 20 '07 #1
2 6694
mattmao
121 100+
Hi.

Because you have commented these line of code.

Just remove the // and see how it works now...
Oct 21 '07 #2
JosAH
11,448 Expert 8TB
i keep getting that error on line 139. i need help please
You really should fix your indentation; it is a mess now. I removed everything
except for the offending method:

Expand|Select|Wrap|Line Numbers
  1.         public static String HTMLFilter(String input){
  2.             String regex[] = {"&","<",">","\""};
  3.             String replace[] = {"&amp;", "&lt;", "&gt;", "&quot;"};
  4.             Matcher m;
  5.             String newString = "";
  6.             String s = input;
  7.             for (int i = 0; 1 < 4; i++) {
  8.                 m = Pattern.compile(regex[i]).matcher(s);
  9.                 newString = (m.find() ? m.replaceAll(replace[i]) : s);
  10.                 s = newString;
  11.             }
  12.  
  13.             return newString;
  14.         //} else { // <--- this was line 139
  15.         //   return input;
  16.        //} 
  17.         }
  18.  
Even if you uncomment those lines the compiler never would've complained
about "unreachable code" because it would be a simple syntax error.
Please clean up your code and try to ask your question again.

kind regards,

Jos
Oct 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: leza | last post by:
I am trying to understand why "continue" keyword is used for, therefore I compiled this code but I got this error message.. why ==================== C:\Program Files\JCreator...
1
by: raizor | last post by:
This email address is unreachable. It has been closed.
1
by: Kepler | last post by:
I have a situation where I need to use a Using statement that creates some records in a database. After that completes, if it completes, I need to do some file creation. Any code I'm putting...
4
by: SteadySteps | last post by:
Hi I migrated a project which compiles correctly on VC 6.0 to VS 2002. However now all I get several warning that all the statements within catch blocks are "unreachable code". How can I correct...
2
by: Hovik Melikyan | last post by:
This code produces a 'unreachable code' warning at line 16 (throw new X ...) with no visible reason: #include <string> class X { std::string msg;
6
by: dfetrow410 | last post by:
Can I do this in an if statement? public string getClass() { counta = counta + 1; if (counta < 2 ) {
4
by: Gernot Frisch | last post by:
I get informed that parts of my code cannot be reached. Did I do something wrong? try { if (login(progstring) > 0) { return 1; // OK } }
8
by: teddysnips | last post by:
I'm new to C# - recent background mainly ASP.NET with VB.NET. Anyhoot, I needed to create a C# statement analogous to VB's IIf: VB.NET Dim e As Boolean e = IIf((CInt(MyVariable) 0), True,...
4
by: EmilyA | last post by:
Hi! I'm not that good at programming, so I was wondering if anyone could tell me why I'm getting an unreachable statement error for lines 18, 35, 68, and 86. import java.util.ArrayList; ...
1
by: HillBilly | last post by:
What does that error mean and why would each break statement be marked as unreachable? It implies the return will --always-- return some --thing-- if even null and no further processing can...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.