`
omygege
  • 浏览: 1353503 次
文章分类
社区版块
存档分类
最新评论

spring step 2 : 又见hello world!

 
阅读更多

1.开发环境

myeclipse 8.5 tomcat 5.5 jdk 1.6

2.又见hello world之j2se版。

http://kin111.blog.51cto.com/738881/171031/

通过xml对beans的描述,使用spring框架动态的反射出所需要的实体类。

首先使用myeclipse新建一个web工程,然后添加spring Capabilities。将自动生成的applicationContext.xml放在src目录中。新建两个类:HelloWorld和SpringClient.代码如下:

applicationContext.xml文件:

文件的目录结构如下:

直接运行SpringClient,可能产生如下的warnings:

解决的办法就是src目录中添加log4j.properties 文件。文件内容如下:

再次运行SpringClient程序,程序只是简单的输出hello world这个亲切的字符串。

3.hello world之j2ee web版。

http://maestric.com/doc/java/spring/hello_world

In 'WEB-INF/web.xml', we declare Spring DispatcherServlet and map '*.html' URLs to it:

Let's now create the Spring configuration file 'WEB-INF/springmvc-servlet.xml' (name based on the servlet name above):

Map URL /hello_world.html to Controller HelloWorldController
Declare View Resolver: when view 'view_name' is called (from the Controller), the file '/jsp/view_name.jsp' will be used

在myeclipse中可以使用下面的方法生成简单的模板:

Let's create the Controller 'WEB-INF/src/springmvc/web/HelloWorldController.java':

Now the view: 'jsp/hello_world.jsp':

将整个的web工程deploy之后,打开:http://localhost:8180/springmvc/hello_world.html,如果一切正常的话,将显示“

This is my message: Hello World MVC!”字符串(由controller传递给页面)。

spring的hello world完毕,其中的主要意义是了解整个spring开发流程,忽略了其中的很多的细节的问题。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics