Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Error in excuting java .class file on a web page

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Error in excuting java .class file on a web page

    In my project ,when user selects .class file it is going to take the file and run the file
    and displays the output ....

    my RunFile.java is
    <code=java>
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import javax.servlet.GenericServlet;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    public class RunFile extends GenericServlet
    {
    InputStream is;
    int c;

    @Override
    public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException
    {

    res.setContentType("text/html");
    PrintWriter pw=res.getWriter();
    //pw.println("hii");
    String f=req.getParameter("file");
    StringExtract se=new StringExtract(f);
    pw.print("hii"+f);
    pw.print("Se"+se);
    String path=se.extractClass();


    String path1="D:/";
    pw.print("path"+path);
    //pw.print("hii"+path1);

    pw.println("<html>");
    pw.println("<body>");

    pw.println(path+"<br><pre>");
    if(!path.equals("null"))
    {
    File file=new File(path);
    pw.print("hii file in loop"+file);
    String ff=file.getName();
    pw.print("file getname"+ff);

    pw.println("<br>");
    try
    {
    pw.println("java "+ff+"+++");
    //pw.println("java "+f+"+++");
    Runtime r=Runtime.getRuntime();
    Process p=r.exec("java "+ff);
    //Process p=r.exec("java "+f);
    //pw.print("Process"+p);

    //pw.print("hii"+ff);
    is=p.getInputStream();
    // pw.print("Stream is"+is);

    pw.print("\n Is read" +is.read());
    pw.print("hii");

    System.out.println("hiiii i am going to c");
    c=is.read();
    //int d=is.read(byte[] );
    pw.print("hii i am c"+c);
    // pw.print("hii"+d);
    while(c!=-1)
    {

    pw.print("hii");
    pw.print((char)c);
    pw.print(c);
    c=is.read();
    //pw.print(c);
    }

    }
    catch(Exception e)
    {
    pw.println("vvvvvvvv");
    }
    }
    else
    {
    pw.print("hii");
    pw.println("MMMMMMMM");
    }
    pw.println("</pre></body></html>");
    pw.close();
    }
    }


    StringExtract.java
    class StringExtract
    {
    String s,s1;
    int pos;
    int p;
    StringExtract(String v)
    {
    s=v;
    }
    boolean extract()
    {

    for(int i=0;i<s.length();i++)
    {
    if(s.charAt(i)=='.')pos=i;

    }

    s1=s.substring(pos+1,s.length());
    if(s1.equalsIgnoreCase("java"))
    return true;
    else
    return false;
    }
    String extractClass()
    {

    for(int i=0;i<s.length();i++)
    {
    if(s.charAt(i)=='.')pos=i;

    }

    s1=s.substring(pos+1,s.length());
    if(s1.equalsIgnoreCase("class"))
    return s.substring(0,pos);
    else
    return "null";
    }
    String extractMain(String b)
    {

    for(int i=b.length();0>i;i--)
    {
    if(b.charAt(i)=='/')p=i;
    }
    return b.substring(p+1,b.length());
    }
    }

    </code>
    in above RunFile ,when we upload any .class file ---it displaying c value =-1

    The data is not displaying


  2. #2
    Administrator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,848
    Thanks
    64
    Thanked 2,645 Times in 2,615 Posts

    Default Re: Error in excuting java .class file on a web page

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Could you explain how your application works? The posted code doesn't have any comments that describe what it does. Where is the -1 displayed?

    Is there a way to test the code without a server? Do you have a testing driver?

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error in excuting java .class file on a web page

    Sir ,my project name-E-Compiler using security editor

    I have completed everything ,except running of java code
    My code is here
    On-line java compiler with security editor.rar

  4. #4
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error in excuting java .class file on a web page

    This is my project code (E-complier using security editor)
    My project details
    On-line java compiler with security editor.rar
    netbeans ide
    OnlineJavaComp.rar

    in this ,i am not able to run the .class file
    not displaying the output ..can anybody help me

Similar Threads

  1. How Do I Automatically Detect Java Version via Web Page without Clicking Anything
    By universityofky in forum Other Programming Languages
    Replies: 0
    Last Post: February 25th, 2013, 11:56 AM
  2. How to download protected web page using JAVA
    By angeles86 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 22nd, 2012, 07:20 AM
  3. Control web page from java swing frame
    By gafaec in forum AWT / Java Swing
    Replies: 2
    Last Post: August 16th, 2011, 08:57 AM
  4. Downloading web page with java script enabled through Java
    By mashimaro in forum Java Networking
    Replies: 1
    Last Post: November 13th, 2010, 08:28 PM
  5. Saving .jsp page as .pdf file while generating report for struts based web application
    By ravindra_kumar_tiwari in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: August 12th, 2008, 09:32 AM