返回:[web工程]Struts2+Spring3.1+Hibernate3.6的集成
下一步:[web工程]集成struts2 mvc
?
创建web工程
?
- 打开eclipse创建java project:demo,如图
? - 创建web工程结构:即
WebRoot
? |-WEB-INF
? ? ?|- classes
? ? ?|- lib
? ? ?|- web.xml
? |- index.jsp
??如图:
- 配置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>
? - 通过配置文件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
1 楼
yaloo
2011-10-20
大哥,我像这样做了,但是报错啊。如下:
警告:A docBase D:\apache-tomcate\webapps\workspace\demo\WebRoot inside the host appBase has been specified, and will be ignored
错误:Error starting static Resources
警告:A docBase D:\apache-tomcate\webapps\workspace\demo\WebRoot inside the host appBase has been specified, and will be ignored
错误:Error starting static Resources
2 楼
skzr.org
2011-10-21
yaloo 写道
大哥,我像这样做了,但是报错啊。如下:
警告:A docBase D:\apache-tomcate\webapps\workspace\demo\WebRoot inside the host appBase has been specified, and will be ignored
错误:Error starting static Resources
警告:A docBase D:\apache-tomcate\webapps\workspace\demo\WebRoot inside the host appBase has been specified, and will be ignored
错误:Error starting static Resources
呵呵,初学tomcat编程吧。
首先tomcat有个默认的应用加载目录:D:\apache-tomcate\webapps
意思是,webapps下的每个文件夹就是web的一个应用。
而你的工作目录是:D:\apache-tomcate\webapps\workspace
所以不行。
你把eclipse工作空间移动到其他目录即可比如:
move D:\apache-tomcate\webapps\workspace到 D:\workspace