2013-04-26 140 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"); 
} 
} 
相關問題