[英]unable to view welcome page in spring mvc
Here is my pom.xml 这是我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.gopal.springmvc</groupId>
<artifactId>springmvctest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springmvctest Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
</dependencies>
<build>
<finalName>springmvctest</finalName>
</build>
</project>
Here is my web.xml file: 这是我的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>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Here is my dispatcher-servlet.xml file: 这是我的dispatcher-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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
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:annotation-config />
<context:component-scan base-package="com.gopal.springmvc"/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
This is my controller: 这是我的控制器:
@Controller
public class RegistrationLoginController {
private static final Logger logger =
Logger.getLogger(RegistrationLoginController.class);
@RequestMapping(value="/", method=RequestMethod.GET)
public String welcome() {
if(logger.isDebugEnabled()){
logger.debug("getWelcome is executed!");
}
System.out.println("Helloooooooo<<<<<");
//@RequestParam
return "welcome";
}
@RequestMapping(value="/login", method=RequestMethod.POST)
public ModelAndView loginForm() {
//@RequestParam
return null;
}
} }
This is my welcome.jsp file which is available in /WEB-INF/jsp/ folder: 这是我的welcome.jsp文件,该文件位于/ WEB-INF / jsp /文件夹中:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Login Form</h2>
</body>
</html>
When I am running this application in tomcat server using eclipse, I am not able to find welcome.jsp page. 当我使用eclipse在Tomcat服务器中运行此应用程序时,无法找到welcome.jsp页面。 I can see in console print message and log message which is present in my controller. 我可以在控制器中看到控制台打印消息和日志消息。 That means request is passing through welcome() method of RegistrationLoginController. 这意味着请求正在通过RegistrationLoginController的welcome()方法传递。 my problem is that I am not able to get welcome.jsp page. 我的问题是我无法获得welcome.jsp页面。 Please help me to find the issue. 请帮助我找到问题。
Thank you. 谢谢。
Try: 尝试:
return <path_of_jsp> + "/welcome.jsp";
To get the path, right click on the file "welcome.jsp" from your IDE and choose Copy Path ( Ctrl+Shift+C for IntelliJ). 要获取路径,请在您的IDE中右键单击文件“ welcome.jsp”,然后选择“复制路径”(对于IntelliJ,则为Ctrl + Shift + C )。
Then paste it to your code like the example above. 然后像上面的示例一样将其粘贴到您的代码中。
your controller method should look something like this: 您的控制器方法应如下所示:
@GetMapping("/")
public String welcome() {
return "C:/WHATEVER_YOUR_PATH_IS/welcome.jsp";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.