首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

LINUX环境TOMCAT施用修改服务器IP

2012-07-02 
LINUX环境TOMCAT应用修改服务器IP?public class ChangeIp extends HttpServlet {protected void service(H

LINUX环境TOMCAT应用修改服务器IP

?

public class ChangeIp extends HttpServlet {protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {Process proc = Runtime.getRuntime().exec("/bin/bash", null, new File("/bin"));PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));out.println("route del default gw 192.168.5.1");out.println("ifconfig wlan0 192.168.5.106 netmask 255.255.255.0");out.println("route add default gw 192.168.5.1 dev wlan0");out.println("/home/sfeer/tomcat/bin/catalina.sh stop");try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}out.println("/home/sfeer/tomcat/bin/catalina.sh start");String line;while ((line = in.readLine()) != null)System.out.println(line);try {proc.waitFor();} catch (InterruptedException e) {e.printStackTrace();}proc.destroy();}}

?

需要注意的几个地方:

wlan0为测试的无线网卡,一般环境为eth0或是eth1有线网卡

修改后建议重启TOMCAT,IP调整后建议执行应用的初始化和销毁程序片

重启TOMCAT可能需要一定时间,调整睡眠时间

?

热点排行