[web工程]创建web工程

返回:[web工程]Struts2+Spring3.1+Hibernate3.6的集成

下一步:[web工程]集成struts2 mvc

创建web工程

  1. 打开eclipse创建java project:demo,如图


     
  2. 创建web工程结构:即

    WebRoot

      |-WEB-INF

         |- classes

         |- lib

         |- web.xml

      |- index.jsp

      如图:

  3. 配置java build path,让编译后的class定位到WebRoot/WEB-INF/classes目录,如图:


     

     web.xml内容如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    	<description>我爱编程</description>
    	<display-name>我爱编程</display-name>
    	<welcome-file-list>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    </web-app>
     
    index.jsp内容如下:
    <%@ page language="java" 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>我爱编程</title>
    		<meta http-equiv="refresh" content="2; url=loginAction.do">
    	</head>
    	<body>
    		<center>
    			<h1>我爱编程!正在跳转到登录页面。。。</h1>
    		</center>
    	</body>
    </html>
    
     
  4. 通过配置文件demo.xml发布web站点到tomcat下:
    tomcat路径下conf/Catalina/localhost/demo.xml,内容如下:
    <?xml version="1.0" encoding="UTF-8" ?>
    <Context path="/demo" docBase="/workspace/demo/WebRoot">
    </Context>
     
    启动tomcat访问index.jsp看看,应该会出现:

    我爱编程!正在跳转到登录页面。。。


    到此一个java的jsp web站点就搭建完毕 下载demo

返回:[web工程]Struts2+Spring3.1+Hibernate3.6的集成

下一步:[web工程]集成struts2 mvc


猜你喜欢

转载自skzr-org.iteye.com/blog/1050787