package dict; import java.io.*; import java.util.Map; import java.util.Hashtable; import javax.servlet.*; import javax.servlet.http.*; public class Get extends HttpServlet { private Map dict = new Hashtable(); public void init() throws UnavailableException { String filename = "/data/words.csv"; ServletContext context = getServletContext(); InputStream is = context.getResourceAsStream( filename ); if ( is != null ) { try { InputStreamReader isr = new InputStreamReader( is ); BufferedReader reader = new BufferedReader( isr ); String line; while ( ( line = reader.readLine() ) != null ) { String[] parts = line.split( "\\|" ); if ( parts.length == 2 ) { if ( dict.containsKey( parts[ 0 ] ) ) { parts[ 1 ] = dict.get( parts[ 0 ] ) + " " + parts[ 1 ]; } dict.put( parts[ 0 ], parts[ 1 ] ); } } is.close(); } catch ( IOException e ) { throw new UnavailableException( "error while reading dictionary" ); } } } public void doGet( HttpServletRequest requete, HttpServletResponse reponse ) throws ServletException, IOException { // initialisation reponse.setContentType( "text/html; charset=\"UTF-8\"" ); PrintWriter doc = reponse.getWriter(); // traitement(s) String mot, dfn = null; mot = requete.getParameter( "mot" ); if ( mot != null ) { dfn = dict.get( mot ); } // génération du document doc.println( "" ); doc.println( "" ); doc.println( " " ); doc.println( " Dictionnaire Latin-Anglais" ); doc.println( " " ); doc.println( " " ); doc.println( " " ); doc.println( " " ); doc.println( "
" ); doc.println( "

" ); doc.println( "

" ); doc.println( " " ); doc.println( " " ); doc.println( " " ); doc.println( " " ); doc.println( " " ); doc.println( " " ); doc.println( " " ); doc.println( " " ); doc.println( " " ); doc.println( " " ); if ( mot != null ) { doc.println( " " ); if ( dfn != null ) { doc.println( " " ); } else { doc.println( " " ); } } doc.println( " " ); doc.println( "
" + mot + "" + dfn + "absent du dictionnaire
" ); doc.println( "
" ); doc.println( "

" ); doc.println( "
" ); doc.println( " " ); doc.println( "" ); // post-traitement(s) doc.close(); } }