我正在尝试获取应用程序加载的第一页。我创建了maven项目,它在web-app下正常运行我在jsp文件夹中创建了一个名为jsp的文件夹我创建了login.jsp 而不是index.jsp,它应该选择jsp文件夹
下的login.jsp <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
控制器
package com.sanria.estimodelling.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.sanria.estimodelling.dto.LoginDTO;
@Controller
public class SampleController {
/* Method to return to login page */
@RequestMapping(value = "login")
public ModelAndView display() {
LoginDTO loginDTO = new LoginDTO();
return new ModelAndView("page-login", "login", loginDTO);
}
}
答案 0 :(得分:0)
我已经改变了我的代码这样的工作正常,任何人都可以审查这个正确的我,如果我知道吗?
Web.xml
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<强>控制器强>
package com.sanria.estimodelling.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.sanria.estimodelling.dto.LoginDTO;
@Controller
public class SampleController {
/* Method to return to login page */
@RequestMapping(value = "/")
public ModelAndView display() {
LoginDTO loginDTO = new LoginDTO();
return new ModelAndView("page-login", "login", loginDTO);
}
}