How to Change the Colors of Text and Background for Cmd in Java

Set terminal background color with Java

I would try with escape codes.

White background is \e[107m, Black foreground \e[30m, i.e. something like the following leads to black on white:

echo -e "\e[107m\e[30mTest String"

In Java you would a System.out.println("\033[107m\033[30m") during startup of the application.

See List of ANSI color escape sequences and http://misc.flogisoft.com/bash/tip_colors_and_formatting for more details

Change color of java console output

You can take a look at the Java Curses Library:
http://sourceforge.net/projects/javacurses/

Here's an entry on how to use it:
http://www.javaworld.com/javaworld/javaqa/2002-12/02-qa-1220-console.html

How to color System.out.println output?

No, but there are third party API's that can handle it

http://www.javaworld.com/javaworld/javaqa/2002-12/02-qa-1220-console.html

Edit: of course there are newer articles than that one I posted, the information is still viable though.

Above link is dead, see this question instead: How to print color in console using System.out.println?

How to extract IP Address in Spring MVC Controller get call?

The solution is

@RequestMapping(value = "processing", method = RequestMethod.GET)
public @ResponseBody ProcessResponse processData(@RequestParam("workflow") final String workflow,
@RequestParam("conf") final String value, @RequestParam("dc") final String dc, HttpServletRequest request) {

System.out.println(workflow);
System.out.println(value);
System.out.println(dc);
System.out.println(request.getRemoteAddr());
// some other code
}

Add HttpServletRequest request to your method definition and then use the Servlet API

Spring Documentation here said in

15.3.2.3 Supported handler method arguments and return types

Handler methods that are annotated with @RequestMapping can have very flexible signatures.
Most of them can be used in arbitrary order (see below for more details).

Request or response objects (Servlet API). Choose any specific request or response type,
for example ServletRequest or HttpServletRequest


Related Topics



Leave a reply



Submit