Все,Spring MVC - приложение без индексной страницы и текстового поля по умолчанию, не отображающее
Весенний новичок здесь.
Я пытаюсь создать весенний mvc (Sping 4.1.6 release). Это приложение не имеет целевой страницы по умолчанию (например, index.jsp, я удалил index.jsp из моего приложения). Это приложение будет вызываться из другого приложения по ссылкам URL или напрямую вводить путь. Моя проблема в том, что я не могу заставить это работать. Когда я набираю localhost: 8080/app/user.jsp (это в папке WEB-INF/jsp) или localhost: 8080/app/jsp/user.jsp (я бы предпочел не использовать этот путь, хотя).
Другой вопрос: я настроил приложение на перенаправление index.jsp на user.jsp в папку WEB-INF (а не WEB-INF/jsp) и Controller @RequestMapping ("/"), пользователь .jsp, но текстовое поле не отображается.
Мой web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>selfsrvc</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>
моя весна-диспетчерская-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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.company"></context:component-scan>
<mvc:annotation-driven />
<mvc:resources mapping="/**" location="/" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value="/WEB-INF/jsp/" />
<property name = "suffix" value=".jsp" />
</bean>
<bean class="org.springframework.context.support.ResourceBundleMessageSource"
id="messageSource">
<property name="basename" value="messages" />
</bean>
Мой контроллер
@Controller
@RequestMapping("/user.jsp")
public class userController {
@RequestMapping(method = RequestMethod.GET)
public String initForm(Model model){
user user = new user();
model.addAttribute("user", user);
System.out.println("IIIIIIIIInside user Controller");
return "user";
}
}
Мой
JSP<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form:form method="POST" commandName="user">
<table>
<tr>
<td>Enter your name:</td>
<td><form:input path="user" /></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
<tr>
</table>
</form:form>
</body>
</html>
Я не уверен, что мне не хватает в обоих сценариях. Благодарю.
EDIT: Предложение от миньона решило мою проблему. Благодарю.