Spring MVC (a) controller that implements the controllers interface

Source: Internet
Author: User
Tags aop xmlns
1.web.xml

	<!--total Distribution Center--
	<servlet>
		<servlet-name>test</servlet-name>
		<servlet-class >org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</ load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>test</ servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>

2.startcontroller.java

Package Com.yw.controller;

Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;

Import Org.springframework.web.servlet.ModelAndView;
Import Org.springframework.web.servlet.mvc.Controller;

public class Startcontroller implements Controller
{

	@Override the public
	Modelandview HandleRequest ( HttpServletRequest arg0,
			httpservletresponse arg1) throws Exception
	{
		System.out.println ("Controller is working ");
		return new Modelandview ("Start");
	}

}

3.test-servlet.xml

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= " Http://www.springframework.org/schema/tx "xsi:schemalocation=" Http://www.springframework.org/schema/beans http:/ /www.springframework.org/schema/beans/spring-beans-2.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP/HTTP Www.springframework.org/schema/aop/spring-aop-2.5.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/HTTP Www.springframework.org/schema/tx/spring-tx-2.5.xsd "> <!--handlemapping based on start.do requests from users Find corresponding controller controllers to process--<bean class= "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" > <property name= "Mappings" > <props> <prop key= "start.do" >startController</prop> &L T;/props> </property> </bean> <!--controller implementation class and package-to-<bean id= "Startcontroller" class= "Com.yw.controller.StartController" ></bean> <!--view parser prefix and suffix, hide jsp, put in Web-inf directory,--<bean class= "Org.springframework.web.servlet.view.UrlBasedViewResolver" > <!--viewresovle view needs to be added, otherwise the error is internationalized using jstlview-- > <property name= "viewclass" value= "Org.springframework.web.servlet.view.JstlView" ></property> < Property name= "prefix" value= "/web-inf/jsp/"/> <property name= "suffix" value= ". jsp"/> </bean> </be Ans>



4.start.jsp (pictured)




5. Operation effect


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: info-contact@alibabacloud.com 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.