struts环境搭建
2012-08-01 21:55
127 查看
1.新建web工程,我这里取名为s281.
2.复制struts最少依赖的jar文件。commons-fileupload-1.2.1, commons-logging-1.0.4 ,freemarker-2.3.15,ognl-2.7.3,struts2-core-2.1.8,xwork-core-2.1.6 把这些文件复制到WEB-INF/lib目录下面去。
3.配置web.xml.内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4.配置struts.xml
内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="feng" namespace="/test" extends="struts-default">
<action name="helloworld" class="cn.feng.action.HelloWorldAction" method="execute" >
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
</package>
</struts>
5.在src目录下建立一个包,叫cn.feng.action.在此包下新建一个文件"HelloWorldAction.java"
内容如下:
package cn.feng.action;
public class HelloWorldAction {
private String msg;
public String getMessage() {
return msg;
}
public String execute(){
msg = "我的第一个struts2应用";
return "success";
}
}
6.在WEB-INF/page目录下新建hello.jsp文件,内容如下:
<%@ page language="java" import="java.util.*" 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>My JSP 'hello.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
${message}
</body>
</html>
部署,然后在浏览器访问localhost:8080/s281/test/helloworld.action即可打印出“这是我的第一个struts2应用”
2.复制struts最少依赖的jar文件。commons-fileupload-1.2.1, commons-logging-1.0.4 ,freemarker-2.3.15,ognl-2.7.3,struts2-core-2.1.8,xwork-core-2.1.6 把这些文件复制到WEB-INF/lib目录下面去。
3.配置web.xml.内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4.配置struts.xml
内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="feng" namespace="/test" extends="struts-default">
<action name="helloworld" class="cn.feng.action.HelloWorldAction" method="execute" >
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
</package>
</struts>
5.在src目录下建立一个包,叫cn.feng.action.在此包下新建一个文件"HelloWorldAction.java"
内容如下:
package cn.feng.action;
public class HelloWorldAction {
private String msg;
public String getMessage() {
return msg;
}
public String execute(){
msg = "我的第一个struts2应用";
return "success";
}
}
6.在WEB-INF/page目录下新建hello.jsp文件,内容如下:
<%@ page language="java" import="java.util.*" 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>My JSP 'hello.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
${message}
</body>
</html>
部署,然后在浏览器访问localhost:8080/s281/test/helloworld.action即可打印出“这是我的第一个struts2应用”
相关文章推荐
- 最新版使用SSH框架(Struts2.x + Spring4.x + Hibernate5.x)搭建JavaWeb开发环境实例
- 用Ant,Struts搭建简单工程应用环境
- Struts2+Spring3+Mybatis3开发环境搭建
- Hibernate3.5.4---web application的xml和annotation环境搭建,整合struts2.1.8
- struts1.3环境搭建示例
- Struts2.x+Spring3.x+Hibernate4.x 整合(一)Struts环境搭建
- Struts 1.x环境搭建和简单应用
- Eclipse搭建struts开发环境
- 使用Maven搭建Struts2+Spring3+Hibernate4的整合开发环境
- Gradle搭建Struts 2.5.14.1基于注解的的开发环境
- struts2.3.24+spring4.1.6+hibernate4.3.11+mysql5.5.25开发环境搭建图文教程
- 使用Maven搭建Struts2+Spring3+Hibernate4的整合开发环境
- 条理清晰的搭建SSH环境之整合Struts和Spring
- Eclipse下搭建struts、spring、hibernate开发环境
- MyEclipse10.7使用Maven搭建Struts2+Spring3+Hibernate4的整合开发环境
- struts环境搭建
- 主题:推荐一个eclipse插件:一键式快速搭建Struts2.0,SSH2环境
- Struts 2 + Hibernate + Spring 开发环境的搭建与数据访问Dao的生成
- struts2.3.16环境搭建要用到的jar包
- 【JAVA Web】mybatis3.3 + struts2.3.24 + mysql5.1.22开发环境搭建及相关说明