The use of the handlermapping of Spring Web MVC is-------simpleurlhandlermapping (there are three kinds of matching methods)

Source: Internet
Author: User
Tags xmlns

Use background:
First step >>>
Create a Controller:loginconstroller under the package Com.spring.web.controller
public class Logincontroller extends abstractcontroller{

Public Modelandview handlerequestinternal (HttpServletRequest request,
HttpServletResponse response) throws exception{

String username=request.getparameter ("UserName");
String pwd=request.getparameter ("pwd");

String msg= "";
Modelandview mav=new Modelandview ("Loginresult"); Note To create a loginresult.jsp page under/web-inf/jsp
if (!username.equals ("Liuxi")) {
Msg= "username does not exist!";
}else if (!pwd.equals ("8888")) {
Msg= "The password is incorrect!";

msg= "Congratulations on your login success!";

Mav.addobject ("msg", MSG);
return MAV;


Step Two >>>>
Configure Web.xml:
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.5"
Xmlns= "Http://"
Xmlns:xsi= "Http://"
Xsi:schemalocation= "Http://
Http:// ">





Step three >>>>
Configure Sample-servlet.xml:

<?xml version= "1.0" encoding= "UTF-8"?>
Xmlns= "Http://"
Xmlns:xsi= "Http://"
xsi:schemalocation= "Http:// Spring-beans-2.0.xsd ">

<bean id= "Logincontroller" class= "Com.spring.web.controller.LoginController"/>

<bean id= "handlermapping" class= "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<!--configuration Method A
<property name= "UrlMap" >
<entry key= "/user/" value-ref= "Logincontroller"/>
<!--configuration Method two
<property name= "Mappings" >
<bean class= "Org.springframework.beans.factory.config.PropertiesFactoryBean" >
<property name= "Location" >
<value></value> <! files should be placed in the Webroot directory at this time! -->
<!--configuration Method three-->
<property name= "Mappings" >
<prop key= "/user/" >loginController</prop>

<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" ><value>/WEB-INF/jsp/</value></property>
<property name= "suffix" ><value>.jsp</value></property>
<property name= "Viewclass" >


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.