- 我有以下 servlet 代码。
- 在控制台中打印以下行时,应以红色打印。 “*连接名称“+cname+”已存在。请尝试使用其他名称”。如何得到这个。
我的servlet代码:
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con =DriverManager.getConnection("jdbc:oracle:thin:@"+host+":"+port+"/"+service,username,password);
con.setAutoCommit(false);
if(con!=null){
if(key == null){
out.println("Connected Successfully");
String rootPath=request.getSession().getServletContext().getRealPath("/");
System.out.println(rootPath);
String propPath=rootPath+"/WEB-INF/";
PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter(propPath+"importedDB.properties", true)));
out1.println(cname+"=jdbc:oracle:thin:@"+host+","+port+","+service+","+username+","+password);
out1.close();
}
else{
out.println("*Connection name "+cname+" already exists. Please try with another name");
}
}else{
out.println("Error in getting connection");
}
}catch(Exception e){
e.printStackTrace();
}
最佳答案
您可以尝试 jlibs ( http://code.google.com/p/jlibs/wiki/AnsiColoring ),它在控制台输出中具有 Ansi 颜色。
关于java - 使用java设置字符串颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15062553/