Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

web server -deprecation problem

[es] :: Java :: web server -deprecation problem

[ Pregleda: 1616 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

anon81718

Član broj: 81718
Poruke: 24
*.bi.dlp306.bih.net.ba.



Profil

icon web server -deprecation problem27.11.2007. u 11:40 - pre 200 meseci
ej drushtvo,poshtovanje...

imam problemcic kada kompajliram code za ovaj web server,trazi mi da to uradim sa -deprecation...ali mi onda javlja greshke...ne znam zashto...i kako ih se rijeshtiti...greshke cete vidjeti prilikom kompajliranja...

evo code:

Code:
import java.net.*;
import java.io.*;
import java.util.*;

public class jhttp extends Thread 
{
    Socket theConnection;
    static File docroot;
    static String indexfile = "index.html";
    


    public jhttp(Socket s) 
    {
        theConnection = s;
    }


    public static void main(String[] args) 
    {
        int thePort;
        ServerSocket ss;
        // get the Document root

        try 
        {
            docroot = new File(args[0]);
        }


        catch (Exception e) 
        {
            docroot = new File(".");
        }

        
        // set the port to listen on

        try 
        {
            thePort = Integer.parseInt(args[1]);
            if (thePort < 0 || thePort > 65535) thePort = 80;
        } 


        catch (Exception e) 
        {
            thePort = 80;
        } 


        try 
        {
            ss = new ServerSocket(thePort);
            System.out.println("Accepting connections on port " 
                + ss.getLocalPort());
            System.out.println("Document Root:" + docroot);


            while (true) 
            {
                jhttp j = new jhttp(ss.accept());
                j.start();
            }

        }


        catch (IOException e) 
        {
            System.err.println("Server aborted prematurely");
        }

        
    }


    public void run() 
    {
        
        String method;
        String ct;
        String version = "";
        File theFile;
        


        try 
        {
            PrintStream os = new PrintStream(theConnection.getOutputStream());
            DataInputStream is = new DataInputStream(theConnection.getInputStream());
            String get = is.readLine();
            StringTokenizer st = new StringTokenizer(get);
            method = st.nextToken();


            if (method.equals("GET")) 
            {
                String file = st.nextToken();
                if (file.endsWith("/")) file += indexfile;
                ct = guessContentTypeFromName(file);


                if (st.hasMoreTokens()) 
                {
                    version = st.nextToken();
                }

                // loop through the rest of the input li
                //     nes 

                while ((get = is.readLine()) != null) 
                {
                    if (get.trim().equals("")) break;
                }


                try 
                {
                    theFile = new File(docroot, file.substring(1,file.length()));
                    FileInputStream fis = new FileInputStream(theFile);
                    byte[] theData = new byte[(int) theFile.length()];
                    // need to check the number of bytes rea
                    //     d here
                    fis.read(theData);
                    fis.close();
                    if (version.startsWith("HTTP/")) 
                    { // send a MIME header
                        os.print("HTTP/1.0 200 OK\r\n");
                        Date now = new Date();
                        os.print("Date: " + now + "\r\n");
                        os.print("Server: jhttp 1.0\r\n");
                        os.print("Content-length: " + theData.length + "\r\n");
                        os.print("Content-type: " + ct + "\r\n\r\n");
                    } // end try

                
                    // send the file
                    os.write(theData);
                    os.close();
                } // end try

                catch (IOException e) 
                { // can't find the file
                    if (version.startsWith("HTTP/")) 
                    { // send a MIME header
                        os.print("HTTP/1.0 404 File Not Found\r\n");
                        Date now = new Date();
                        os.print("Date: " + now + "\r\n");
                        os.print("Server: jhttp 1.0\r\n");
                        os.print("Content-type: text/html" + "\r\n\r\n");
                    } 

                    os.println("<HTML><HEAD><TITLE>File Not Found</TITLE></HEAD>");
                    os.println("<BODY><H1>HTTP Error 404: File Not Found</H1></BODY></HTML>");
                    os.close();
                }

            }

            else 
            { // method does not equal "GET"
                if (version.startsWith("HTTP/")) 
                { // send a MIME header
                    os.print("HTTP/1.0 501 Not Implemented\r\n");
                    Date now = new Date();
                    os.print("Date: " + now + "\r\n");
                    os.print("Server: jhttp 1.0\r\n");
                    os.print("Content-type: text/html" + "\r\n\r\n"); 
                }

                os.println("<HTML><HEAD><TITLE>Not Implemented</TITLE></HEAD>");
                os.println("<BODY><H1>HTTP Error 501: Not Implemented</H1></BODY></HTML>");
                os.close();
            }

        }


        catch (IOException e) 
        {

        }


        try 
        {
            theConnection.close();
        }


        catch (IOException e) 
        {
        }

    }



    public String guessContentTypeFromName(String name) 
    {
        if (name.endsWith(".html") || name.endsWith(".htm")) return "text/html";
        else if (name.endsWith(".txt") || name.endsWith(".java")) return "text/plain";
        else if (name.endsWith(".gif") ) return "image/gif";
        else if (name.endsWith(".class") ) return "application/octet-stream";
        else if (name.endsWith(".jpg") || name.endsWith(".jpeg")) return "image/jpeg";
        else return "text/plain";
    }

}
 
Odgovor na temu

anon315

Član broj: 315
Poruke: 1657
*.adsl-3.sezampro.yu.



+13 Profil

icon Re: web server -deprecation problem27.11.2007. u 15:47 - pre 200 meseci
Stavi ovo:

Code:

BufferedReader is = new BufferedReader(new InputStreamReader(theConnection.getInputStream()));


umesto ovog:

Code:

DataInputStream is = new DataInputStream(theConnection.getInputStream());
 
Odgovor na temu

anon81718

Član broj: 81718
Poruke: 24
*.bi.dlp6.bih.net.ba.



Profil

icon Re: web server -deprecation problem28.11.2007. u 12:45 - pre 200 meseci
super...s bufferreaderom radi...nema greshaka....HVALA PUNO....

ali me zanima ovo sa vracanjem stranica...da li mora postojati neka index.html stranica u folderu ili shta...jer kada pokrenem javlja mi Exception in thread "main" java.lang.NoClassDefFoundError: jhttp/java

nije do classpath-a jer mi ostali programi rade OK...nemam rjeshenje...mozda je neko pametniji... ;)

[Ovu poruku je menjao NENO_ROCK dana 28.11.2007. u 14:04 GMT+1]
 
Odgovor na temu

anon315

Član broj: 315
Poruke: 1657
*.adsl-3.sezampro.yu.



+13 Profil

icon Re: web server -deprecation problem28.11.2007. u 13:08 - pre 200 meseci
http://java.sun.com/docs/books...getStarted/problems/index.html
 
Odgovor na temu

[es] :: Java :: web server -deprecation problem

[ Pregleda: 1616 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.