Buggy code:
@ WebServlet ( "//SearchProject" ) @ SuppressWarnings ( "serial" ) public class SearchProject extends HttpServlet { protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { } protected void doPost ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { HttpSession session = request . getSession ( false ) ; Writer wt = response . getWriter ( ) ; if ( null == session ) { wt . write ( "Invalid<seq2seq4repair_space>Access" ) ; return ; } Byte userType = ( ( Byte ) ( session . getAttribute ( "userType" ) ) ) ; if ( ( null == userType ) || ( userType != ( Login . ADMIN ) ) ) { wt . write ( "Invalid<seq2seq4repair_space>Access" ) ; return ; } String pname = request . getParameter ( "name" ) ; String department = request . getParameter ( "department" ) ; String year = request . getParameter ( "year" ) ; String semester = request . getParameter ( "semester" ) ; if ( ( ( ( ( pname . length ( ) ) == 0 ) && ( ( department . length ( ) ) == 0 ) ) && ( ( year . length ( ) ) == 0 ) ) && ( ( semester . length ( ) ) == 0 ) ) { wt . write ( "Invalid<seq2seq4repair_space>Parameter" ) ; return ; } boolean first = true ; try { StringBuilder query = new StringBuilder ( "SELECT<seq2seq4repair_space>*<seq2seq4repair_space>FROM<seq2seq4repair_space>Project<seq2seq4repair_space>" ) ; if ( ( pname . length ( ) ) > 0 ) { query . append ( ( ( "WHERE<seq2seq4repair_space>name<seq2seq4repair_space>LIKE<seq2seq4repair_space>'%" + pname ) + "%'<seq2seq4repair_space>" ) ) ; first = false ; } if ( ( department . length ( ) ) > 0 ) { if ( first ) { query . append ( "WHERE<seq2seq4repair_space>" ) ; first = false ; } else { query . append ( "AND<seq2seq4repair_space>" ) ; } query . append ( ( ( "department='" + department ) + "'<seq2seq4repair_space>" ) ) ; } if ( ( year . length ( ) ) > 0 ) { if ( first ) { query . append ( "WHERE<seq2seq4repair_space>" ) ; first = false ; } else { query . append ( "AND<seq2seq4repair_space>" ) ; } query . append ( ( ( "year=" + year ) + "<seq2seq4repair_space>" ) ) ; } if ( ( semester . length ( ) ) > 0 ) { if ( first ) { query . append ( "WHERE<seq2seq4repair_space>" ) ; first = false ; } else { query . append ( "AND<seq2seq4repair_space>" ) ; } query . append ( ( "semester=" + semester ) ) ; } Connection conn = MySqlConnection . getConnection ( ) ; Statement stmt = conn . createStatement ( ) ; ResultSet rs = stmt . executeQuery ( query . toString ( ) ) ; ArrayList < Project > projects = new ArrayList < Project > ( ) ; HashSet < String > departments = new HashSet < String > ( ) ; while ( rs . next ( ) ) { projects . add ( new Project ( rs . getInt ( "id" ) , rs . getString ( "name" ) , rs . getString ( "department" ) , rs . getShort ( "year" ) , rs . getByte ( "semester" ) ) ) ; departments . add ( rs . getString ( "department" ) ) ; } rs . close ( ) ; stmt . close ( ) ; conn . close ( ) ; wt . write ( "<ul>\n\t" ) ; for ( String dpmt : departments ) { wt . write ( ( ( "<li>\n\t\t<div<seq2seq4repair_space>onClick=\"toggle(\'" + dpmt ) + "\');\">\n\t\t\t" ) ) ; wt . write ( ( ( "<span<seq2seq4repair_space>class=\"expandButton\"<seq2seq4repair_space>id=\"span" + dpmt ) + "\">[+]<//span>\n" ) ) ; for ( String d : Department . departments ) { if ( d . substring ( 0 , dpmt . length ( ) ) . equals ( dpmt ) ) { wt . write ( ( ( "\t\t\t" + d ) + "\n\t\t<//div>\n\t\t" ) ) ; break ; } } wt . write ( ( ( "<ul<seq2seq4repair_space>class=\"block\"<seq2seq4repair_space>id=\"ul" + dpmt ) + "\">\n\t\t\t" ) ) ; for ( Project p : projects ) { if ( p . department . equals ( dpmt ) ) { wt . write ( ( ( ( ( "<li<seq2seq4repair_space>>[" + ( p . id ) ) + "]<seq2seq4repair_space>" ) + ( p . name ) ) + "<seq2seq4repair_space>(" ) ) ; wt . write ( ( ( ( ( p . year ) + "~" ) + ( ( p . year ) + 1 ) ) + "<seq2seq4repair_space>Semester<seq2seq4repair_space>" ) ) ; if ( ( p . semester ) == 0 ) wt . write ( "1<seq2seq4repair_space>and<seq2seq4repair_space>2" ) ; else wt . write ( p . semester ) ; } } <START_BUG> wt . write ( "<//ul>\n\t<//li>" ) ; <END_BUG> } wt . write ( "<//ul>" ) ; } catch ( SQLException e ) { e . printStackTrace ( ) ; wt . write ( "Database<seq2seq4repair_space>Error" ) ; } } }

Fix:
wt . write ( "<//ul>\n\t<//li>\n" ) ;