这是一个简单的SpringMVC多模块项目,这里我想通过action"showlogin.do"从index. jsp发出请求,然后通过LoginController.java加载login.jsp。
我正在尝试构建WAR文件,然后想在Tomcat服务器上运行。在tomcat服务器上运行时,它显示index. jsp,但当我单击链接(showlogin.do)时,它会给我错误,如HTTP状态404-未找到。
网址-
整体报价
文件夹结构-
生物技术-测试[家长]
生物技术-数据[资料库]
Biotech-service[Service],pom. xml具有存储库的依赖关系
biotech-web, pom.xml对服务有依赖
index. jsp[Biotech-web:src/main/webapp/index.jsp]
<html>
<body>
<h3>WELCOME</h3>
<a href="showlogin.do" target="_blank">Click here to login</a>
</body>
</html>
web. xml[Biotech-web:src/main/webapp/WEB-INF/web.xml]
<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>*.do</url-pattern>
</servlet-mapping>
</web-app>
tiles. xml[Biotech-web:src/main/webapp/WEB-INF/tiles.xml]
<tiles-definitions>
<definition name="baseTemplate" id="baseTemplate" template="/WEB-INF/layout/baselayout.jsp">
<put-attribute name="title" value="Biotech"/>
<put-attribute name="header" value="/WEB-INF/layout/jsp/header.jsp"/>
<put-attribute name="body" value="${body}"/>
<put-attribute name="footer" value="/WEB-INF/layout/jsp/footer.jsp"/>
</definition>
<definition name="login" id="login" extends="baseTemplate">
<put-attribute name="body" value="/WEB-INF/jsp/login.jsp" />
<put-attribute name="title" type="string" value="Login Page" />
</definition>
</tiles-definitions>
调度器-servlet. xml[Biotech-web:src/main/webapp/WEB-INF/调度器-servlet.xml]
<context:component-scan base-package="com.pack.controller" />
<context:component-scan base-package="com.pack.services" />
<context:component-scan base-package="com.pack.repository" />
<mvc:annotation-driven />
<context:annotation-config />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
LoginController.java控制器
package com.pack.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class LoginController {
@RequestMapping("/showlogin")
public String showlogin() {
System.out.println("--------------login Controller----------");
return "login";
}
}
您的请求映射只有/showlogin
,它应该是/showlogin.do