JSP executes External commands

Source: Internet
Author: User

Here is an example:

<% @ Page contenttype = "text/html; charset = big5" session = "false" Import = "Java. Io. *" %>

<HTML>

<Head>

<Title> </title>

<Meta http-equiv = "Content-Type" content = "text/html; charset = big5">

</Head>

<Body>

<%

Runtime runtime = runtime. getruntime ();

Process = NULL;

String line = NULL;

Inputstream is = NULL;

Inputstreamreader ISR = NULL;

Bufferedreader BR = NULL;

String IP = "add the IP address you want to ping here ";

// Modify the above IP Address

Try

{

Process worker runtime.exe C ("ping" + IP );

Is = process. getinputstream ();

ISR = new inputstreamreader (is );

BR = new bufferedreader (ISR );

Out. println ("<PRE> ");

While (line = Br. Readline ())! = NULL)

{

Out. println (line );

Out. Flush ();

}

Out. println ("</PRE> ");

Is. Close ();

ISR. Close ();

BR. Close ();

}

Catch (ioexception E)

{

Out. println (E );

Runtime. Exit (1 );

}

%>

</Body>

</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.