我刚刚在spring tool suit中创建了一个示例spring mvc项目(没有进行任何修改),当我执行它时,我将按照index.jsp获得输出。但在此之后,我只在view文件夹中添加一个index.html页面,并进行了以下两个更改
>
在控制器类i中添加:返回“index”;
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".html" />
在Pivotal Server Developer Edition V3.1上执行更改后的代码时,我得到HTTP状态404(请求的资源不可用错误。)
据我所知,不需要其他改变。请提供一些建议。提前致谢
HomeController.java
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "index";
}
}
servlet-context.xml
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".html" />
</beans:bean>
<context:component-scan base-package="com.srio.tata" />
web.xml
contextConfigLocation/web-inf/spring/root-context.xml
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
是否配置了viewResolver
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
</bean>
我正在学习Spring MVC,当我试图运行http://localhost:8080/firstspringmvc/welcome.html时,它会出现错误 HTTP状态404-/firstspringmvc/welcome.html
我试图在Eclipse中制作一个spring hello world程序。这是代码 index.jsp HelloWorldController.java 当我使用像http://localhost:8080/springmvcbasic/hello这样的url时,我得到的是 我已经从这里拿走了代码
我试图测试Spring MVC,并编写了以下代码: web.xml:http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd“version=”3.0“> Apache Tomcat/8.0.39 Tomcat控制台日志:
问题是:我的index.jsp和web.xml总是进入HTTP404和500 我用的是Tomcat6。 这来自index.jsp: 当我注册时: 我点击名字和姓氏,进入404,信息是: 类型状态报告 根据请求,下面是 这里还有项目树:
为什么我在web-inf/view//admin得到双斜线。我是Java MVC的新手,所以请给我任何建议,我做错了什么? 这是我的代码` 控制器-
我试图创建一个基本的Spring MVC应用程序,它引发了以下错误: HTTP状态404-Servlet welcome不可用 我的项目结构 我的web.xml: 我的index.jsp: 我的WelcomePage.jsp: 提前谢了。