Spring MVC 学习笔记1 - First Helloworld by Eclipse
reference:http://www.gontu.org
1. 下载 Spring freamworks 4.0.0 RELEASE
2. 下载 commons-logging-1.2-bin
3. 在Eclipse Luna Service Release 1 (4.4.1)中新建Dynamic Web App
4. 配置服务器平台:Window - show view - servers ; "Click to creat server";Apache/Tomcat v8.0
5. Tomcat installation directory; "next"; "finish"
右键点击项目名,Properties, TargetRuntimes, 勾“Apache Tomcat v8.0”
6. 添加jar文件入/WebContet/WEB-INF/lib
从这里来:Spring freamworks 4.0.0 RELEASE + commons-logging-1.2.jar
7. 写第1个文件:web.xml
a.它是截流器
<web-app>
b.<display-name>
c.<servlet> - name - class
d.<servlet-mapping> -name ,url-pattern
8. 写第2个文件:$servletname-dispacher.xml$
a.<beans ...></beans>
b.<bean id=HandlerMapping, ... /><!--HandlerMapping-->
<bean name="/welcome.html" class="edu.bit.helloController" />
c.<bean name=welcome.html, class=/>
d.<bean id="viewResolver"<!--ViewResolver>
9. 写第3个文件:helloController.java
在HanderMapping 中指定了 Controller: JavaResources/src/edu.bit.helloController.java
creat package "edu.bit" at JavaResources/src
creat class file: helloController.java
写HelloController.class
10.写Hellopp.jsp
helloController.java中指定了:
ModelAndView modelandview = new ModelAndView("Hellopp");
故需要 Hellopp.jsp 作为ViewResolver的解析目标
11. Run - Run As - Run on Server
【Java Web开发Tips集锦】
1. 特别注意,在日后的学习中,每次修改了代码再run之前,最好Project>>clean..以后,再run
2. eclipse新建jsp页面默认编码设置UTF-8:Window→preferences→General→Content Types,然后打开右边Text选中JSP,在下面Default encoding:那里输入编码,然后点击Update ,ok, window - preferences - Web - JSP Files页 - Creating files框,Encoding选项: UTF - 8 .点"Apply"就行了。