在servlet里面写就可以了
引入一系列包
import java.io.IOException
import java.io.PrintWriter
import javax.servlet.ServletException
import javax.servlet.ServletRequest
import javax.servlet.ServletResponse
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import java.io.*
public class Servlet1 extends HttpServlet {
public void doGet(ServletRequest req,ServletResponse res)throws ServletException, IOException{try{PrintWriter pw=res.getWriter()//在浏览器输出需要
pw.println("<script<script")}catch(exception e){="" e.printstacktrace()="" 为发现调试错误}}}=""
如何使一个java程序,一执行,就打开本地某目录下的html文件?比如abc.html, 就像双击打开那样! 15
public static void main(String args[]) throws Exception
{
File file = new File("abc.html")
Runtime ce=Runtime.getRuntime()
System.out.println(file.getAbsolutePath())
ce.exec(file.getAbsolutePath())
}
像这样,想打开同目录下的abc.html,怎么不行呢?
恩,你的命令不正确,怎么会打开呢?
试试我给你的代码吧
import java.io.File
public class TestRuntime {
/**
* @param args
*/
public static void main(String args[]) throws Exception
{
File file = new File("abc.html")
Runtime ce=Runtime.getRuntime()
System.out.println(file.getAbsolutePath())
ce.exec("cmd /c start "+file.getAbsolutePath())
}
}
只要在你的同目录下有abc.html,就可以打开了