我在一个控制器中有2个请求映射,而第二个请求映射无法找到(在DispatcherServlet中找不到带有URI [/LeeSong_login_v2/verify.htm]的HTTP请求的映射,名称为“dispatcher”)
我的调度员 - servlet:
<mvc:annotation-driven/>
<context:component-scan base-package="controller" />
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<!-- <bean class="com.LeeSong.controller.loginController" id="loginController" /> -->
<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
<prop key="login.htm">loginController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<bean name="loginController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="login" />
控制器:
@Controller
public class loginController{
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(){
return new ModelAndView("login");
}
@RequestMapping(value = "/verify", method = RequestMethod.POST)
public ModelAndView verify(
@RequestParam("uname") String userid,
@RequestParam("pass") String pwd) {
ModelAndView mv = new ModelAndView("home");
System.out.println("begin logging...");
try {
List<Users> lst = LeeSongDAO.layDS();
System.out.println("INPUT DETAILS: user: " + userid + " pass: " + pwd);
for (Users lst1 : lst) {
System.out.println("user: " + lst1.getUsername() + " pass: " + lst1.getPassword());
if (userid.equals(lst1.getUsername())) {
if (pwd.equals(lst1.getPassword())) {
System.out.println("credentials correct!");
return mv;
}
}
}
System.out.println("wrong credentials!");
} catch (Exception e) {
}
return new ModelAndView("wronglogin");
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
我仍然是春天新手,我可能会在这里做一些新手错误。任何帮助将不胜感激。谢谢!在发布后约2小时内,我试着回答一些评论,需要休息一下。
答案 0 :(得分:0)
<context:component-scan base-package="controller" />
&#34;控制器&#34;必须特定于您的控制器的地址。就我而言:&#34; com.springtest1.controller&#34;