我看起來不同的鏈接和網站,但無法解決資源不可用的問題。我通過以前的計算器答案,但無法解決。我正在使用Intellij 2016.2.2資源不可用
這是我的Spring MVC的HelloWorld示例。
控制器類:
package com.himal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* Created by Himal Acharya on 2016-09-17.
*/
@Controller
public class HelloWorld {
@RequestMapping("/hi")
public ModelAndView helloWorld(){
ModelAndView modelAndView=new ModelAndView("Hello");
modelAndView.addObject("message","Hello and Hi");
return modelAndView;
}
}
我已經把彈簧調度 - servlet.xml中和web.xml在WEB-INF。
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>SpringHelloWorldDemo12</display-name>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
和Spring調度-servlet.xml的是:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<context:component-scan base-package="com.himal"/>
<mvc:annotation-driven/>
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property></bean>
</beans>
我已經把我的JSP文件下的WEB /頁。運行http://localhost:8888/hi。它產生時,下面的錯誤
但每次:
請求的資源不可用
<%--
Created by IntelliJ IDEA.
User: Himal Acharya
Date: 2016-09-17
Time: 3:49 PM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>${message}</h1>
</body>
</html>
中的IntelliJ我的項目結構爲。
我花了整整一天,但無法弄清楚。
您是否將應用程序部署爲根Web應用程序?否則,它可能在'http:// localhost:8888/SpringHelloWorldDemo12/hi'。 –
我沒有部署爲根網絡應用程序。但我試過http:// localhost:8888/SpringHelloWorldDemo12/hi ..同樣發生了同樣的問題 –
And ...然後,您選擇部署應用程序的上下文路徑是什麼? –