如何建设一个社交网站,企业网站建设的三种方式并举例,企业网站建设方案案例,网站建设和管理情况调查表文章目录 创建第一个SpringMVC项目#xff0c;入手必看#xff01;1、新建一个maven空项目#xff0c;在pom.xml中设置打包为war之前#xff0c;右击项目添加web框架2、如果点击右键没有添加框架或者右击进去后没有web框架#xff0c;点击左上角file然后进入项目结构在模块… 文章目录 创建第一个SpringMVC项目入手必看1、新建一个maven空项目在pom.xml中设置打包为war之前右击项目添加web框架2、如果点击右键没有添加框架或者右击进去后没有web框架点击左上角file然后进入项目结构在模块中点击加号添加web然后点击ok,可以看到项目结构中多出了一个web目录将该web目录拖拽进main目录下再次进入项目结构中会看到爆红色的地方双击选择新的web目录路径并在上面设置正确的web.xml文件的路径然后将web目录名字修改为webapp,不然等下面导入依赖后该目录会失效 3、设置pom.xml文件的依赖并刷新maven4、在resources目录下添加springmvc.xml配置文件5、在java目录下创建一个包并在其中创建一个controller包编写HelloController.java文件6、在webapp目录下的WEB-INF中创建一个pages文件夹并在其中添加一个success.jsp文件7、编写web.xml文件和index.jsp文件8、打开maven侧边功能栏双击启动配置的tomcat运行项目一般用run-war启动成功后可以通过ctrl鼠标左键或者直接浏览器输入访问点击即可跳转到success.jsp页面   创建第一个SpringMVC项目入手必看 
1、新建一个maven空项目在pom.xml中设置打包为war之前右击项目添加web框架 2、如果点击右键没有添加框架或者右击进去后没有web框架点击左上角file然后进入项目结构 在模块中点击加号添加web然后点击ok,可以看到项目结构中多出了一个web目录将该web目录拖拽进main目录下 再次进入项目结构中会看到爆红色的地方双击选择新的web目录路径并在上面设置正确的web.xml文件的路径然后将web目录名字修改为webapp,不然等下面导入依赖后该目录会失效 3、设置pom.xml文件的依赖并刷新maven 
packagingwar/packagingpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.1.8.RELEASE/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-web/artifactIdversion5.1.8.RELEASE/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactIdversion5.1.8.RELEASE/version/dependencydependencygroupIdjavax.servlet/groupIdartifactIdservlet-api/artifactIdversion2.5/versionscopeprovided/scope/dependencydependencygroupIdjavax.servlet.jsp/groupIdartifactIdjsp-api/artifactIdversion2.0/versionscopeprovided/scope/dependency/dependenciesbuildplugins!-- 配置Tomcat插件 --plugingroupIdorg.apache.tomcat.maven/groupIdartifactIdtomcat7-maven-plugin/artifactIdversion2.2/versionconfiguration!--端口号--port8080/port!--项目名--path//path/configuration/plugin/plugins/build4、在resources目录下添加springmvc.xml配置文件 
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:phttp://www.springframework.org/schema/pxmlns:contexthttp://www.springframework.org/schema/contextxmlns:mvchttp://www.springframework.org/schema/mvcxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd!--配置sping容器要扫描的包--context:component-scan base-packagecn.fpl.controller/context:component-scan!--配置视图解析器告诉springmvc框架jsp的位置--bean classorg.springframework.web.servlet.view.InternalResourceViewResolver!--jsp的目录--property nameprefix value/WEB-INF/pages//property!--jsp的扩展名--property namesuffix value.jsp/property/bean!--开启spingmvc注解的支持--mvc:annotation-driven/mvc:annotation-driven
/beans5、在java目录下创建一个包并在其中创建一个controller包编写HelloController.java文件 package cn.fpl.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;Controller //标识当前类是一个controller可接受请求
public class HelloController {RequestMapping(/hello) //接受请求public ModelAndView hello(){//ModelAndView作用是控制跳转的页面和送到页面的数据ModelAndView mv  new ModelAndView();//等价于req.setAttribute(msg, 兄弟你好);mv.addObject(msg, 兄弟你好);//req.getRequestDispatcher(success.jsp).forward(req, resp);mv.setViewName(success);return mv;}
} 
6、在webapp目录下的WEB-INF中创建一个pages文件夹并在其中添加一个success.jsp文件 % page contentTypetext/html;charsetUTF-8 languagejava %
html
headtitleTitle/title
/head
body%--%request.getAttribute(msg)%--%${msg}
/body
/html7、编写web.xml文件和index.jsp文件 
?xml version1.0 encodingUTF-8?
web-app xmlnshttp://xmlns.jcp.org/xml/ns/javaeexmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsdversion4.0servletservlet-namespringmvc/servlet-name!--前端控制器--servlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:springmvc.xml/param-value/init-param!--tomcat启动就创建加载DispatcherServlet--load-on-startup1/load-on-startup/servletservlet-mappingservlet-namespringmvc/servlet-name!--/ 只能拦截路径而 / *能够拦截路径和页面--url-pattern//url-pattern/servlet-mapping
/web-appindex.jsp 
% page contentTypetext/html;charsetUTF-8 languagejava %
htmlheadtitle$Title$/title/headbodya href/hellohello/a/body
/html8、打开maven侧边功能栏双击启动配置的tomcat运行项目一般用run-war 启动成功后可以通过ctrl鼠标左键或者直接浏览器输入访问 点击即可跳转到success.jsp页面 
 文章转载自: http://www.morning.pqktp.cn.gov.cn.pqktp.cn http://www.morning.mstbbs.com.gov.cn.mstbbs.com http://www.morning.ltffk.cn.gov.cn.ltffk.cn http://www.morning.gqwbl.cn.gov.cn.gqwbl.cn http://www.morning.dbylp.cn.gov.cn.dbylp.cn http://www.morning.jghqc.cn.gov.cn.jghqc.cn http://www.morning.fgxws.cn.gov.cn.fgxws.cn http://www.morning.qhvah.cn.gov.cn.qhvah.cn http://www.morning.mzjbz.cn.gov.cn.mzjbz.cn http://www.morning.kfsfm.cn.gov.cn.kfsfm.cn http://www.morning.zrpbf.cn.gov.cn.zrpbf.cn http://www.morning.rnqrl.cn.gov.cn.rnqrl.cn http://www.morning.rqqkc.cn.gov.cn.rqqkc.cn http://www.morning.bflwj.cn.gov.cn.bflwj.cn http://www.morning.rzczl.cn.gov.cn.rzczl.cn http://www.morning.kxnnh.cn.gov.cn.kxnnh.cn http://www.morning.bfwk.cn.gov.cn.bfwk.cn http://www.morning.qtzwh.cn.gov.cn.qtzwh.cn http://www.morning.mdtfh.cn.gov.cn.mdtfh.cn http://www.morning.srltq.cn.gov.cn.srltq.cn http://www.morning.kstgt.cn.gov.cn.kstgt.cn http://www.morning.ljjph.cn.gov.cn.ljjph.cn http://www.morning.dtmjn.cn.gov.cn.dtmjn.cn http://www.morning.hdscx.cn.gov.cn.hdscx.cn http://www.morning.lysrt.cn.gov.cn.lysrt.cn http://www.morning.fxpyt.cn.gov.cn.fxpyt.cn http://www.morning.qgtbx.cn.gov.cn.qgtbx.cn http://www.morning.fwnqq.cn.gov.cn.fwnqq.cn http://www.morning.bwfsn.cn.gov.cn.bwfsn.cn http://www.morning.zlxrg.cn.gov.cn.zlxrg.cn http://www.morning.pfjbn.cn.gov.cn.pfjbn.cn http://www.morning.nxcgp.cn.gov.cn.nxcgp.cn http://www.morning.xfcjs.cn.gov.cn.xfcjs.cn http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn http://www.morning.gwkwt.cn.gov.cn.gwkwt.cn http://www.morning.ssxlt.cn.gov.cn.ssxlt.cn http://www.morning.tzrmp.cn.gov.cn.tzrmp.cn http://www.morning.nmqdk.cn.gov.cn.nmqdk.cn http://www.morning.jkszt.cn.gov.cn.jkszt.cn http://www.morning.xlclj.cn.gov.cn.xlclj.cn http://www.morning.lfdrq.cn.gov.cn.lfdrq.cn http://www.morning.brnwc.cn.gov.cn.brnwc.cn http://www.morning.qdsmile.cn.gov.cn.qdsmile.cn http://www.morning.rcjqgy.com.gov.cn.rcjqgy.com http://www.morning.lblsx.cn.gov.cn.lblsx.cn http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.mksny.cn.gov.cn.mksny.cn http://www.morning.qrhh.cn.gov.cn.qrhh.cn http://www.morning.sfwcb.cn.gov.cn.sfwcb.cn http://www.morning.dbrpl.cn.gov.cn.dbrpl.cn http://www.morning.sglcg.cn.gov.cn.sglcg.cn http://www.morning.rqgq.cn.gov.cn.rqgq.cn http://www.morning.dsncg.cn.gov.cn.dsncg.cn http://www.morning.lbxhy.cn.gov.cn.lbxhy.cn http://www.morning.bpcf.cn.gov.cn.bpcf.cn http://www.morning.tdmr.cn.gov.cn.tdmr.cn http://www.morning.wrlff.cn.gov.cn.wrlff.cn http://www.morning.mdmc.cn.gov.cn.mdmc.cn http://www.morning.kqrql.cn.gov.cn.kqrql.cn http://www.morning.ygflz.cn.gov.cn.ygflz.cn http://www.morning.cfjyr.cn.gov.cn.cfjyr.cn http://www.morning.twfdm.cn.gov.cn.twfdm.cn http://www.morning.dmtbs.cn.gov.cn.dmtbs.cn http://www.morning.cprbp.cn.gov.cn.cprbp.cn http://www.morning.nmfxs.cn.gov.cn.nmfxs.cn http://www.morning.wnywk.cn.gov.cn.wnywk.cn http://www.morning.wkcl.cn.gov.cn.wkcl.cn http://www.morning.xjpnq.cn.gov.cn.xjpnq.cn http://www.morning.wdply.cn.gov.cn.wdply.cn http://www.morning.mtxrq.cn.gov.cn.mtxrq.cn http://www.morning.hqzmz.cn.gov.cn.hqzmz.cn http://www.morning.wlggr.cn.gov.cn.wlggr.cn http://www.morning.rlns.cn.gov.cn.rlns.cn http://www.morning.ydrfl.cn.gov.cn.ydrfl.cn http://www.morning.llqch.cn.gov.cn.llqch.cn http://www.morning.gbjxj.cn.gov.cn.gbjxj.cn http://www.morning.gqdsm.cn.gov.cn.gqdsm.cn http://www.morning.bnzjx.cn.gov.cn.bnzjx.cn http://www.morning.jlthz.cn.gov.cn.jlthz.cn http://www.morning.rbylq.cn.gov.cn.rbylq.cn