Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.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 如何在Spring控制器中显示文件_Java_Html_Spring_Jsp_Spring Mvc - Fatal编程技术网

Java 如何在Spring控制器中显示文件

Java 如何在Spring控制器中显示文件,java,html,spring,jsp,spring-mvc,Java,Html,Spring,Jsp,Spring Mvc,我有个问题。这是我第一次这样做。我使用SpringREST控制器生成了一个随机数程序,并在JSP中显示 现在我尝试的是映射HTML文件,显示我在JSP中得到的内容。但我面临着这个错误 找不到URI为的HTTP请求的映射 我也尝试过各种网站,但不了解其中的错误 这里我有HTML的highchart,我每5秒刷新一次页面。所以,我从服务器获取y轴的值,时间绘制在x轴上。我还陷入了来自HTML文件的Ajax调用中。我不知道如何从服务器获取一个轴值,从时间获取另一个轴值 我正在这里粘贴代码--- 我的控

我有个问题。这是我第一次这样做。我使用SpringREST控制器生成了一个随机数程序,并在JSP中显示

现在我尝试的是映射HTML文件,显示我在JSP中得到的内容。但我面临着这个错误

找不到URI为的HTTP请求的映射

我也尝试过各种网站,但不了解其中的错误

这里我有HTML的highchart,我每5秒刷新一次页面。所以,我从服务器获取y轴的值,时间绘制在x轴上。我还陷入了来自HTML文件的Ajax调用中。我不知道如何从服务器获取一个轴值,从时间获取另一个轴值

我正在这里粘贴代码---

我的控制器-

package com.xyz.rest.temperature.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.lucid.rest.temperature.exception.InvalidRangeException;
import com.lucid.rest.temperature.exception.NegativeNumberException;
import com.lucid.rest.temperature.util.RandomNumberGenerator;

@RestController
public class ReadingController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String getReading() throws NegativeNumberException,
            InvalidRangeException {
        return new Integer(new RandomNumberGenerator().generateRandomNumber(
                100, 50)).toString();
        }

     @RequestMapping(value = "/staticPage", method = RequestMethod.GET)
       public String redirect() {

          return "redirect:/jsp/hello.htm";
       }
}
我的调度程序Servlet--


我的web.xml文件是-

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
   <display-name>Temperature Reading</display-name>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
        <welcome-file>hello.html</welcome-file>
  </welcome-file-list>

   <servlet>
      <servlet-name>TemperatureReading</servlet-name>
      <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
      </servlet-class>
           <init-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>/WEB-INF/TemperatureReading-servlet*.xml</param-value>
     </init-param>
      <load-on-startup>1</load-on-startup>
     </servlet>

   <servlet-mapping>
      <servlet-name>TemperatureReading</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>

   <error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/jsp/index.jsp</location>
  </error-page>

</web-app>

温度读数
index.jsp
hello.html
温度读数
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/TemperatureReading servlet*.xml
1.
温度读数
/
404
/WEB-INF/jsp/index.jsp
我的JSP是-

<%@page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Random generator</title>
<%@ page language='java'%>
<%@ page import='java.*'%>
<%@ page
    import="com.xyz.rest.temperature.controller.ReadingController"%>
<%
    ReadingController obj = new ReadingController();
%>
</head>
<body>
    <%
        String i = obj.getReading();
    %>
    <%=i%>
</body>
</html>

随机发生器
我的HTML文件是--


温度
// 
所以我几乎把所有的东西都贴上了。请帮助我找出错误所在,以及如何克服HTMl中的轴值问题

感谢您的帮助。如果你什么都不懂,请发表评论。谢谢

我强烈建议读者阅读控制器的工作原理和使用方法。我强烈建议读者阅读控制器的工作原理和使用方法。
<%@page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Random generator</title>
<%@ page language='java'%>
<%@ page import='java.*'%>
<%@ page
    import="com.xyz.rest.temperature.controller.ReadingController"%>
<%
    ReadingController obj = new ReadingController();
%>
</head>
<body>
    <%
        String i = obj.getReading();
    %>
    <%=i%>
</body>
</html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="robots" content="noindex, nofollow">
  <meta name="googlebot" content="noindex, nofollow">

  <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>

  <style type="text/css">

  </style>

  <title>Temprature</title>


<script type='text/javascript'>//<![CDATA[


$(document).ready(function() {

var options = {
    chart: {
        renderTo: 'cpuhealth',
        type: 'column'
    },
    title: {
        text: 'CPU Usage'
    },
    events: {
          load: function() {

        // set up the updating of the chart each second
        var series = this.series[0];
        setInterval(function(){
        var chart = new Highcharts.Chart(options);
        $.getJSON('http://url-to-json-file/index.php', function(jsondata) {
            options.series[0].data = JSON.parse(jsondata.cpu);
        });
        }, 5000);
       }              
    },
    yAxis: {
        labels: {
            formatter: function() {
                return this.value + ' %';
            }
        },
        title: {
            text: 'Usage (%)'
        }
    },
    xAxis: {
        title: {
            text: 'CPU Core ID#'
        }
    },
    tooltip: {
        formatter: function() {
            return 'CPU Core: <b>' + this.x + '</b><br>Usage <b>' + this.y + '%</b>';
        }
    },
    legend: {
        enabled: false
    },
    series: [{}]
};

}

//]]> 

</script>


</head>

<body>
  <script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>


</body>

</html>