Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改Java的HTML输出_Java_Html_Spring_Spring Boot_Web - Fatal编程技术网

更改Java的HTML输出

更改Java的HTML输出,java,html,spring,spring-boot,web,Java,Html,Spring,Spring Boot,Web,我有以下代码: @Controller public class GatesController { @RequestMapping ("/gates") public static String qualityGates(String x) throws IOException { try { System.out.println("\n------QualityGates------"); URL toCon

我有以下代码:

@Controller
public class GatesController {

    @RequestMapping ("/gates")

    public static String qualityGates(String x) throws IOException {
        try {
            System.out.println("\n------QualityGates------");
            URL toConnect = new URL(x);
            HttpURLConnection con = (HttpURLConnection) toConnect.openConnection();
            System.out.println("Sending 'GET' request to URL : " + x);

            BufferedReader in = new BufferedReader(
                    new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }

            in.close();

            //Cast the JSON-File to a JSONObject
            JSONObject res = new JSONObject(response.toString());
            JSONArray gates = new JSONArray(res.getJSONObject("projectStatus").getJSONArray("conditions").toString());
            JSONObject test = new JSONObject(res.getJSONObject("projectStatus").toString());

            String a = ("\nThe current Project-Status is: " + test.get("status") + "\n");
            String b = "";
            for (int i = 0; i < gates.length(); i++) {
                String status = gates.getJSONObject(i).getString("status");
                String metric = gates.getJSONObject(i).getString("metricKey");
                b = b + ("<\b>Status: " + status + " | Metric: " + metric);

            }

            System.out.println(a+b);
            return a + b;
        } catch (Exception e) {
            System.out.println(e);
            return String.format("Error");
        }
    }
目前的问题是,该网站的外观如下:

但我希望每一个指标都有一行,而不是一行。 如你所见,我试图在字符串处添加 你有办法解决这个问题吗?这是我的第一个web应用程序,我有点卡住了

我感谢你的帮助

你的“”会破坏它。如果删除它并添加换行符“\n”,它应该可以工作。 像这样:

String a = ("\nThe current Project-Status is: " + test.get("status") + "\n");
String b = "";
for (int i = 0; i < gates.length(); i++) {
   status = gates.getJSONObject(i).getString("status");
   String metric = gates.getJSONObject(i).getString("metricKey");
   b = b + ("Status: " + status + " | Metric: " + metric + "\n");
}

然后,输出将显示换行符。这样,您可以应用进一步的格式设置。

首先,谢谢!我只是添加了
而不是
,效果非常好!伟大的很高兴听到这个消息。我本应该亲眼看到的,但我很着急。如果我的回答解决了你的问题,请接受我的回答。你为什么不使用MVC?@kulsin对不起,MVC?
String a = ("\nThe current Project-Status is: " + test.get("status") + "\n");
String b = "";
for (int i = 0; i < gates.length(); i++) {
   status = gates.getJSONObject(i).getString("status");
   String metric = gates.getJSONObject(i).getString("metricKey");
   b = b + ("Status: " + status + " | Metric: " + metric + "\n");
}
@GetMapping(value = "/gates", produces = "text/plain")