Struts2+Hibernate+Spring框架筹建(一)
Struts2+Hibernate+Spring框架搭建(一)
一:搭建Struts2的框架
1.首先新建一个"WebProject",名称为----FirstSshProject
2.将Struts2所需要的Jar包拷贝到“WEB-INF”下面的 lib目录中
Struts2所需要的Jar包如下

3.在src目录下新建包“com.wl.struts.action”,在此包下新建一个名为“loginAction”的类,并且继承“ActionSupport”。重写这个类的“execute()”方法
loginAction.java的代码如下:
4.
1)修改WebRoot下面的“index.jsp”文件
2)在WebRoot目录下面添加success.jsp文件
3)在WebRoot目录下面添加error.jsp文件
5.在src目录下面新建一个struts.xml的文件
6.修改“Web.xml”的配置信息,将Struts2的配置信息添加进去
7.使用Tomcat部署项目,启动Tomcat,输入"http://localhost:8080/FirstSshProject_001"

点击“test action ”连接之后,结果如下:

经过以上操作步骤,Strut2的环境搭建完毕。
一:搭建Struts2的框架
1.首先新建一个"WebProject",名称为----FirstSshProject
2.将Struts2所需要的Jar包拷贝到“WEB-INF”下面的 lib目录中
Struts2所需要的Jar包如下
3.在src目录下新建包“com.wl.struts.action”,在此包下新建一个名为“loginAction”的类,并且继承“ActionSupport”。重写这个类的“execute()”方法
loginAction.java的代码如下:
package com.wl.struts.action; import com.opensymphony.xwork2.ActionSupport; @SuppressWarnings("serial") public class loginAction extends ActionSupport { @Override public String execute() throws Exception { return SUCCESS; } }
4.
1)修改WebRoot下面的“index.jsp”文件
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%> <% 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 'index.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> This is my JSP page. <br> <a href="login.action">test action</a> </body> </html>
2)在WebRoot目录下面添加success.jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%> <% 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 'success.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> Success. <br> </body> </html>
3)在WebRoot目录下面添加error.jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%> <% 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 'error.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> Error. <br> </body> </html>
5.在src目录下面新建一个struts.xml的文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "http://struts.apache.org/dtds/struts-2.1.7.dtd"> <struts> <package name="login" namespace="/" extends="struts-default"> <action name="login" class="com.wl.struts.action.loginAction"> <result name="success">/success.jsp</result> <result name="error">/error.jsp</result> </action> </package> </struts>
6.修改“Web.xml”的配置信息,将Struts2的配置信息添加进去
<?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"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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> </web-app>
7.使用Tomcat部署项目,启动Tomcat,输入"http://localhost:8080/FirstSshProject_001"
点击“test action ”连接之后,结果如下:
经过以上操作步骤,Strut2的环境搭建完毕。
1 楼
lame_cat
2012-06-17
按照楼主的方法走了一遍为什么最后action找不到呢,404了