操作JBuilder 2005开辟Spring实例[Java编程]
本文“操作JBuilder 2005开辟Spring实例[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
1. 下载spring包,网址以下:
http://www.springframework.org/download.html
解压后的目录中包含了dist、lib等子目录
2. 在JBuilder2005中增添spring库,挑选菜单Tools-Configure-Libraries,在弹出的对话框中点击New按钮,输入spring库的名称:spring,点击Add按钮,将dist目录中的全部jar文件增添到spring库中
3. 新建工程文件,选菜单File-New Project,给工程文件取名为myProject
设置工程文件的属性,选菜单Project-Project Properties,挑选Tomcat作为服务器,将spring库加入Path/Required Libraries.因为例子顶用到了log4j,将包含了log4j的库加入Path/Required Libraries,注意到lib目录下有两个子目录log4j和jakarta-commons,它们的用法是差别的,以下面的代码片断所示:
log4j
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
public class SpringappController implements Controller {
/** Logger for this class and subclasses */
static Logger logger = Logger.getLogger(SpringappController.class);
jakarta-commons
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class SpringappController implements Controller {
/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());
4. 新建Web模块,选菜单File-New,给Web模块取名为springapp
5. 新建hello.jsp文件以下:
<%@ page contentType="text/html; charset=Big5" %>
<html>
<head><title>Example :: Spring Application</title></head>
<body>
<h1>Hello - Spring Application</h1>
<p>Greetings.</p>
</body>
</html>
6. 新建类文件SpringappController.java以下:
package spring;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
public class SpringappController implements Controller {
/** Logger for this class and subclasses */
// protected final Log logger = LogFactory.getLog(getClass());
static Logger logger = Logger.getLogger(SpringappController.class);
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
logger.info("SpringappController - returning hello view");
return new ModelAndView("hello.jsp");
}
}
7. 改正web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
以上是“操作JBuilder 2005开辟Spring实例[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |