记录关于spring MVC入门遇见的问题
2015-05-10 11:43
274 查看
本人初入JAVA WEB。虽然学习路途遥远,但我确要一步步行走。
在学习spring MVC时第一个遇见的问题是SVN获取源代码时遇见的验证失败错误。原因是URL:https://src.springframework.org/svn/spring-framework/ 代码服务器改为了https://github.com/SpringSource/spring-framework/
.
第二个遇见的问题是
严重: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/xxxx]错误。原因是需要导入commons-logging.jar包。关于它们的关系:spring主要是javabean管理的,aop用作权限,日志管理方面,当然也会用到日志记录,这就需要引入日志包commons-logging.jar.
第三个遇见的问题是
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleUrlHandlerMapping' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'helloControl' is defined错误。原因竟然是spring-servlet.xml里面<prop>的内容与<bean>不配对。哈哈。
经过这些问题后,终于进入了spring MVC的HelloWord!,哈哈
下面列出.java、.xml、.jsp的代码.
spring-servlet.xml
web.xml
HelloWord.java
hello.jsp
index.jsp
在学习spring MVC时第一个遇见的问题是SVN获取源代码时遇见的验证失败错误。原因是URL:https://src.springframework.org/svn/spring-framework/ 代码服务器改为了https://github.com/SpringSource/spring-framework/
.
第二个遇见的问题是
严重: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/xxxx]错误。原因是需要导入commons-logging.jar包。关于它们的关系:spring主要是javabean管理的,aop用作权限,日志管理方面,当然也会用到日志记录,这就需要引入日志包commons-logging.jar.
第三个遇见的问题是
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleUrlHandlerMapping' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'helloControl' is defined错误。原因竟然是spring-servlet.xml里面<prop>的内容与<bean>不配对。哈哈。
经过这些问题后,终于进入了spring MVC的HelloWord!,哈哈
下面列出.java、.xml、.jsp的代码.
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- Bean头部 --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" > <property name="mappings"> <props> <prop key="/hello.do">helloControl</prop> </props> </property> </bean> <bean id="helloControl" class="controller.HelloWord"></bean> </beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- 注意导入commons-logging.jar包 --> </web-app>
HelloWord.java
package 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 HelloWord implements Controller { public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mav = new ModelAndView("hello.jsp"); mav.addObject("message", "Good luky!"); return mav; } }
hello.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'hello.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 获取值: ${message} </body> </html>
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <form action="test/login.do" method="POST"> <input type="text" name="userName"/> <input type="password" name="password"/> <input type="submit" value="commit"/> </form> </body> </html>
相关文章推荐
- 关于在django入门时遇见的读取模版时碰到的编码问题
- 记录关于搭建mysql主从复制中遇见的问题
- 关于cloudstack中遇见的一些问题处理笔记
- 记录 9402 一下在Myeclipse的关于 The type 'Application' is not API 的问题
- Unity学习日常问题记录二-关于刚体的碰撞和物理材质(设定了材质不反弹的一种错误)
- hibernate sqlite dialect 关于select sum(xx) 出错问题记录
- 关于自定义view使用,命名空间问题,记录而已
- 关于spring-cloud-config配置中心远程拉取有时失败问题记录
- 公司关于见习产品经理的会议我的问题及领导答复记录
- 关于重装系统后电脑无声音问题记录
- 关于控制台输入的代码怎么跑单元测试的问题记录
- 关于spring mvc加载本地xsd文件问题
- 关于eclipse下利用tomcat调试jsp的一些问题的解决记录
- 首个spring mvc 测试例子搭建遇到问题记录
- 关于Excel导入的问题记录
- spring mvc使用过程中关于spring:bind和绑定java.util.Date遇到的问题
- 记录下关于AlamManager的几个问题
- 关于android从入门到精通4.1.9范例1出现的闪退的问题
- 关于在 Linux 下多个不相干的进程互斥访问同一片共享内存的问题,记录锁,好文章
- android中关于位移动画TranslateAnimation开始和结束时闪动问题的记录