شبكة شباب IT ترحب بالزوار الكرام

اهلا وسهلا بك في شبكة و منتديات شباب IT ترحب بالزوار الكرام وتدعوكم للتسجل معنا ..

انضم إلى المنتدى ، فالأمر سريع وسهل

شبكة شباب IT ترحب بالزوار الكرام

اهلا وسهلا بك في شبكة و منتديات شباب IT ترحب بالزوار الكرام وتدعوكم للتسجل معنا ..

شبكة شباب IT ترحب بالزوار الكرام

هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.
شبكة شباب IT ترحب بالزوار الكرام

منتديات شباب IT للتكنولوجيا معنى أخر ...

~ JSP Source Code ~ Get-1-2010-almlf_com_sk7z3hec


    ~ JSP Source Code ~

    avatar
    ViRuSMaN
    المدير العام
    المدير العام


    ذكر
    تاريخ التسجيل : 31/07/2009
    تاريخ الميلاد : 01/01/1988
    عدد المساهمات : 72
    العمر : 36
    الموقع : https://mmit.yoo7.com

    ~ JSP Source Code ~ Empty ~ JSP Source Code ~

    مُساهمة من طرف ViRuSMaN الخميس سبتمبر 24, 2009 8:24 am

    Internationalized Web Applications JavaServer Pages


    This JSP source code is about Internationalized Web Applications: JavaServer Pages

    كود

    /*


    Java Internationalization


    By Andy Deitsch,David Czarnecki




    ISBN: 0-596-00019-7


    O'Reilly


    */





    import java.io.*;


    import java.util.*;


    import javax.servlet.*;


    import javax.servlet.http.*;





    public class JSPLocaleNegotiatorServlet extends HttpServlet {





    private static final String defaultJSP = "/jsp/default_en_US.jsp";


    private static final String jspExtension = ".jsp";





    public void doGet(HttpServletRequest request,HttpServletResponse response) throws


    IOException,ServletException {





    Locale usersLocale = request.getLocale();





    StringBuffer jspWithLocale = new StringBuffer();


    if (request.getParameter("jsppage") != null) {


    jspWithLocale.append(request.getParameter("jsppage"));


    jspWithLocale.append("_");


    jspWithLocale.append(usersLocale.toString());


    jspWithLocale.append(jspExtension);


    } else


    jspWithLocale.append(defaultJSP);





    response.setLocale(usersLocale);


    getServletConfig().getServletContext()


    .getRequestDispatcher(jspWithLocale.toString())


    .forward(request,response);


    }


    }
    avatar
    ViRuSMaN
    المدير العام
    المدير العام


    ذكر
    تاريخ التسجيل : 31/07/2009
    تاريخ الميلاد : 01/01/1988
    عدد المساهمات : 72
    العمر : 36
    الموقع : https://mmit.yoo7.com

    ~ JSP Source Code ~ Empty رد: ~ JSP Source Code ~

    مُساهمة من طرف ViRuSMaN الخميس سبتمبر 24, 2009 8:25 am

    Uploading A File To A Server And DB

    كود


    Step 1: Ensure that your setup allows for "multipart" form encryption and you either have it set to unlimited or to a specific amount. Be sure to limit your upload amount as hypnodisc pointed out you don't want a 50 meg upload.




    Here is the resin.conf settings i have used in my test.




    <caucho.com>


    <http-server app-dir='g:myprojects' class-update-interval='2'>


    <http port='8080'/>




    <!-- enable multipart-mime/form processing -->


    <multipart-form upload-max='4096'/>




    <error-log id='log/error.log'/>


    <servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>


    <servlet-mapping url-pattern='*.jsp' servlet-name='com.caucho.jsp.JspServlet'/>


    </http-server>


    </caucho.com>






    Step 2: HTML




    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">




    <html>


    <head>


    <title>Untitled</title>


    </head>




    <body>




    <form name="frm" method="get" action="upload.jsp" enctype="multipart/form-data">




    <input type="File" name="myupload">




    <input type="submit" name="submit" value="Submit">




    </form>






    </body>


    </html>




    Step 3: JSP




    This time I have included the complete JSP test page I have used. All comments and server output are still in place.




    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">




    <html>


    <head>


    <title>Untitled</title>


    </head>




    <body>




    <%@ page language="java"


    import=""


    %>




    <%= createFile(request) %>






    <%!




    public String createFile(javax.servlet.http.HttpServletRequest request) {


    String uploadContent = "";


    String origFileName = "";


    String aSQLCommand = "";





    try {


    String aUploadedFile = request.getParameter("myupload");





    // if a filename was given


    if ( aUploadedFile != null ) {


    java.io.File file = new java.io.File(aUploadedFile);


    byte buffer[] = new byte[(int)file.length()];


    System.out.println("Reading file: " + aUploadedFile );


    System.out.println("Filename: " + aUploadedFile.substring( aUploadedFile.lastIndexOf("")+1) );


    origFileName = aUploadedFile.substring( aUploadedFile.lastIndexOf("")+1);


    java.io.InputStream fileData = new java.io.FileInputStream(aUploadedFile);


    fileData.read(buffer);


    fileData.close();





    /*


    * Create your file on the server


    */


    System.out.println("Writing file...");


    java.io.OutputStream outPutFile = new java.io.FileOutputStream( "g:/myprojects/uploads/" +origFileName );


    outPutFile.write(buffer);


    outPutFile.close();


    // Put the entire file content into a String field


    uploadContent = new String(buffer); // New String object





    System.out.println("File created");


    } else {


    System.out.println("File not created");


    }





    /*


    * Comment out this code if you do not want to add the complete file content to a database field.


    * This example only works with text files as I am only uploading the content to a large text field.


    * **********************************************************************************


    */





    /*


    * Create your specific DB INSERT statment here to add the file content to a DB field called fileContent


    */


    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();


    java.sql.Connection conn;


    // Change this line to match your DB user and password


    conn = java.sql.DriverManager.getConnection("databaselocation", "username", "password");


    java.sql.Statement stmt = conn.createStatement();


    aSQLCommand = "insert into TESTENV1.TABLE1 ( testFile, fileContent ) values ( '" + origFileName + "','" + uploadContent + "' ) ";





    /*


    * Display the SQL command for analysis if needed.


    */


    System.out.println("SQL: " + aSQLCommand);





    /*


    * Now take the returned data and save that to Oracle


    */


    int myValue = stmt.executeUpdate( aSQLCommand );


    if ( myValue > 0 ) {


    System.out.println("SQL: Insert of data was successful");


    } else {


    System.out.println("SQL: Insert of data failed!");


    }





    stmt.close(); // Close SQL statement


    conn.close(); // Close DB Connection





    /*


    * **********************************************************************************


    */





    } catch(Exception ex) {


    System.out.println("Error creating file: " + ex );


    }


    return uploadContent; // Return the newly uploaded content to the screen


    } // CreateFile





    %>





    </body>


    </html>





    One thing to keep in mind is that with the basic resin.conf I gave your file uploads will end up in your resin root (server root) directory most likely so if you give the exact server path you want the files to go to then they will go there instead (make sure the path exists first though)





    Now some may notice that I have added here a part ot retrieve the original filename. That was not in my first example as we use a special naming convention for our files I removed it. I added back the basic part ot get the original name but you can do as we do as well and give a custom name to the file.
    avatar
    ViRuSMaN
    المدير العام
    المدير العام


    ذكر
    تاريخ التسجيل : 31/07/2009
    تاريخ الميلاد : 01/01/1988
    عدد المساهمات : 72
    العمر : 36
    الموقع : https://mmit.yoo7.com

    ~ JSP Source Code ~ Empty رد: ~ JSP Source Code ~

    مُساهمة من طرف ViRuSMaN الخميس سبتمبر 24, 2009 8:26 am

    Using The Application Object
    كود

    <HTML>


    <HEAD>


    <TITLE>Using the Application Object</TITLE>


    </HEAD>





    <BODY>


    <H1>Using the Application Object</H1>


    <%


    Integer counter = (Integer)session.getAttribute("counter");


    String heading = null;


    if (counter == null) {


    counter = new Integer(1);


    } else {


    counter = new Integer(counter.intValue() 1);


    }





    session.setAttribute("counter",counter);





    Integer applicationCounter = (Integer)application.getAttribute("applicationCounter");


    if (applicationCounter == null) {


    applicationCounter = new Integer(1);


    } else {


    applicationCounter = new Integer(applicationCounter.intValue() 1);


    }





    application.setAttribute("applicationCounter",applicationCounter);


    %>





    You have visited this page <%=counter%> times.


    <BR>


    This page has been visited by all users <%=applicationCounter%> times.


    </BODY>


    </HTML>

      الوقت/التاريخ الآن هو الثلاثاء مايو 14, 2024 6:46 pm