好吧,我知道在这里有20个帖子有同样的问题,但没有一个似乎帮助我,所以这可能是重复的,但我已经读过所有其他帖子和他们都没有解决我的问题,所以肯定有一些我做错了,或者我没有对前面提到的问题做出正确的修改。spring请求映射404状态
我正在尝试使用Spring创建一个小应用程序,而且我仍在尝试使用它,但我花了4天的时间试图找出错误,但我不能。每当我尝试从控制器获取jsp时,我仍然会收到HTTP状态404。无非是通过Tomcat的404种状态,没有别的...
WebAppController:
@Controller
public class WebAppController {
@RequestMapping(value="/login", method = RequestMethod.GET)
public String login() {
System.out.println("You have entered the login maprequest");
return "test1";
}
}
的web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Hotel Application</display-name>
<servlet>
<servlet-name>WebApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>WebApp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
webApp.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.iquestgroup" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
这种配置的作品在一个简单的maven项目中只有上面提到的那个。问题是,完全相同的事情不能在包含3个模块(持久性,服务和webapp)的maven项目中使用。在webapp中,我复制了完全相同的东西,当我在服务器上运行它时,我获得了404 http状态...即使模块正在成功构建。
L.E.被接受的答案的第一部分指的是由Spring开始的人员所犯的一个常见的servlet映射错误。我的问题与它无关,最终在最初回答后我最终删除了它。为了不成为读者困惑,接受的答案的第一部分指的是下面的代码:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
您编辑问题'/ *'出了问题!现在答案没有意义。它说要更改'/* url-pattern>',但_ ***不会再出现在问题***中。 –
2016-05-16 22:26:11
@StephenP这个问题在初步回应后进行了编辑,我在回答的评论中宣布。保留/ *似乎毫无意义,尽管这不是我的问题,Stack Overflow上还有许多问题,这些问题完全是指。 我理解你的观点,我认为你是对的,这可能会让人困惑,所以我会在问题的最后提到这一点。 – 2016-05-16 22:59:14