SpringMVC配置+小例子
本文内容纲要:
先加入SpringMVC的jar包,这个官网上有,下载下来放到lib文件夹下。
web.xml文件:
springMVC-servlet.xml文件:
HelloWorldController.java文件:
packagecom.mcm.web.controller;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importorg.springframework.web.servlet.ModelAndView;
importorg.springframework.web.servlet.mvc.Controller;
publicclassHelloWorldControllerimplementsController{
publicModelAndViewhandleRequest(HttpServletRequestarg0,
HttpServletResponsearg1)throwsException{
System.out.println("HellomySpringMVC!");
returnnewModelAndView("/aaa");
}
}
aaa.jsp文件:
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
项目的文件目录如图所示:
部署、运行后结果:
后台输出:HellomySpringMVC!
浏览器显示aaa.jsp页面(地址栏:http://localhost:8080/SpringMVC_demo1/test/helloworld)
本文内容总结:
原文链接:https://www.cnblogs.com/dyllove98/p/3155434.html