2013-04-26 86 views
0

是否可以使用STS在Web服务器上运行程序? 我目前使用的MVC框架,所以我猜我需要在控制器的形式做到这一点?或者,如果没有,还有其他的方法吗?使用Spring Tool Suite在Web服务器上运行程序

所以我想知道的是: 如何编写这样的控制器,或者其他方式。

我在Apache Tomcat/7.0.39上运行Web服务器,并且我已经将Windows 7作为我的当前操作系统。

非常感谢!

+0

嘿,你正在使用PHP [只有前两天(http://stackoverflow.com/问题/ 16187352/make-a-web-server-carry-a-program)':-)'。 – halfer 2013-04-26 20:18:30

回答

0

我最终编写了一个控制器,它调用了一个在CMD中执行.bat文件的类。这为我做了诡计。

控制器包含这样的代码:

@RequestMapping(value = "/execute", method = RequestMethod.GET) 
public void execute(Model model){ 
    CommandExecution ce = new CommandExecution("path for .bat file"); 
    model.addAttribute("name", ce); 
} 

类CommandExecution:

public class CommandExecution { 
public CommandExecution(String commandline) { 
    try { 
     String line; 
     Process p = Runtime.getRuntime().exec(commandline); 
     BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); 
     while ((line = input.readLine()) != null) { 
      System.out.println(line); 
     } 
     input.close(); 
    } catch (Exception err) { 
     err.printStackTrace(); 
    } 
} 

//This main method is only used to be able to se if the .bat file is properly written 
public static void main(String argv[]) { 
    new CommandExecution("path to .bat file"); 
} 
} 
相关问题