我已经开始在基于Maven的项目中使用Spring MVC。我的项目目录结构是 https://laravel.com/docs/5.4/validation#conditionally-adding-rules
web.xml的内容
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.web.controller"/>
<bean name="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>/WEB-INF/config.properties</value>
</list>
</property>
</bean>
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:resources mapping="/js/**" location="/js/"/>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
servetContext的内容是
@Controller
public class LoginController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String signIn() {
return "sign-in";
}
}
在LoginController中,我定义了一个将处理初始HttpRequest
的方法defined( 'ABSPATH' ) or die( 'Error: 120' );
/**
* Check if WooCommerce is active
**/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
/**
* Register a custom menu page.
*/
function wpdocs_register_my_custom_menu_page() {
add_menu_page(
__( 'Amazon Affiliate Dashboard', 'textdomain' ),
'Amazon Affiliate',
'manage_options',
'amazon-affiliate/dashboard.php',
'',
plugins_url( 'amazon-affiliate/assets/images/icon2.png' ),
6
);
}
add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );
}else{
}
请求登录页面时
它给我404找不到错误。你能告诉我在这里为整个设置做了什么错误。
答案 0 :(得分:1)
您应该有一个索引页面,直接放在webapp文件夹下,用于每个Web应用程序,这是访问应用程序时加载的第一个页面。
将此内容包含在您的web.xml中
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
重定向页面(jsp)可以是:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("signin"); %>
然后你可以将“signin”映射到spring的indexcontroller。哪个会将您的“登录”页面视为视图
答案 1 :(得分:0)
I have done mistake one mistake in Parent POM.xml, where i have defined scope as provided for spring-mvc so that it is not packaged with in lib folder. That is why dispatcher class was not found. I have checked the log and solved the issue. Thank you for all.