• 周六. 7 月 13th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

unreachable statement – Java From 5gw.org

King Wang

4 月 10, 2022

xmlns=”http://www.w3.org/1999/xhtml” dir=”ltr” lang=”en”>
unreachable statement – Java
/**
* Bytes CSS
* Style: ‘bytes.answers’; Style ID: 18
*/
@import url(“/clientscript/vbulletin_css/style-12635a82-00018.css”);

 
 
470,370 Members | 1,585 Online

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 6382


(adsbygoogle = window.adsbygoogle || []).push({});

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


Message
 
Cancel Changes

Post your reply

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

Similar topics


3 posts

views

Thread by leza |
last post: by


1 post

views

Thread by raizor |
last post: by


6 posts

views

Thread by dfetrow410 |
last post: by


4 posts

views

Thread by Gernot Frisch |
last post: by


8 posts

views

Thread by teddysnips |
last post: by


1 post

views

Thread by HillBilly |
last post: by


reply

views

Thread by perto1 |
last post: by


reply

views

Thread by cosinus |
last post: by

By using this site, you agree to our Privacy Policy and Terms of Use.


(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-90111-7’, ‘bytes.com’);
ga(‘send’, ‘pageview’);

loadBytesTracking()

//0){location.replace(‘https://bytes.com/showthread.php?p=’+cpostno);};} }

if(typeof window.orig_onload == “function”) window.orig_onload();
}

//]]>

发表回复