注:文章中的所有图片均在附件中明白表明  

首先要安装jdk1.6以及tomcat6和myeclipse 对于这些配置的安装 这里不再细细说明 



其次是下载struts2 

第一步:去struts21的官网 http://struts.apache.org/2.1.6/index.html 

点击以下图1中的的download now。下载图二中的全出就可以。

下载后解压待用; 



第二步; 

打开myeclipse tomcat的集成较简单,不多讲;新建一个web project 取名为struts2。 

第三步。 

在刚刚下载的struts2-1-6文件夹下的lib中复制出例如以下六个文件 

  commons-logging-1.0.4.jar 

  freemarker-2.3.8.jar  

  ognl-2.6.11.jar  

  struts2-core-2.0.6.jar 

  xwork-2.0.1.jar 

以及(由于是struts2-1-6版本号的。所以一下这个文件也不可缺少) 

commons-fileupload-1.2.1 



然后粘贴到WebRoot/WEB-INF/lib就可以; 

第四步: 

WebRoot文件夹下新建一个login.jsp 

代码例如以下 

login.jsp

  1. <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  7. <html>
  8. <head>
  9. <base href="<%=basePath%>">
  10. <title>My JSP 'login.jsp' starting page</title>
  11. <meta http-equiv="pragma" content="no-cache">
  12. <meta http-equiv="cache-control" content="no-cache">
  13. <meta http-equiv="expires" content="0">
  14. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  15. <meta http-equiv="description" content="This is my page">
  16. <!--
  17. <link rel="stylesheet" type="text/css" href="styles.css">
  18. -->
  19. </head>
  20. <body>
  21. <form action="login.action" method="post">
  22. username: <input name="username" type="text"><br>
  23. password: <input name="password" type="password"><br>
  24. <input type="submit" value="submit">
  25. </form>
  26. </body>
  27. </html>

第五步: 

改动WEB-INF下的web.xml文件 

代码例如以下 

web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="2.4"
  3. xmlns="http://java.sun.com/xml/ns/j2ee"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  6. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  7. <filter>
  8. <filter-name>struts2</filter-name>
  9. <!-- 控制器 -->
  10. <filter-class>
  11. org.apache.struts2.dispatcher.FilterDispatcher
  12. </filter-class>
  13. </filter>
  14. <filter-mapping>
  15. <filter-name>struts2</filter-name>
  16. <!-- 不论什么请求均有过滤器 -->
  17. <url-pattern>/*</url-pattern>
  18. </filter-mapping>
  19. </web-app>

第六步: 

新建action 

在src文件夹下新建包com.test.action 

在包中新建一个action代码例如以下 

LoginAction.java

  1. package com.test.action;
  2. public class LoginAction
  3. {
  4. //getter和setter方法   就是依据这里的方法名来匹配client的信息
  5. public String getUsername() {
  6. return username;
  7. }
  8. public void setUsername(String username) {
  9. this.username = username;
  10. }
  11. public String getPassword() {
  12. return password;
  13. }
  14. public void setPassword(String password) {
  15. this.password = password;
  16. }
  17. public String execute() throws Exception
  18. {
  19. return "success";
  20. }
  21. //相应表单上的
  22. private String username;
  23. private String password;
  24. }

第七步: 

struts配置文件 



在src文件夹下新建一个struts.xml代码例如以下:

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  4. "http://struts.apache.org/dtds/struts-2.0.dtd">
  5. <struts>
  6. <package name="struts2" extends="struts-default">
  7. <action name="login" class="com.test.action.LoginAction">
  8. <!-- result没有名字是默认的success -->
  9. <result name="success">/result.jsp</result>
  10. </action>
  11. </package>
  12. </struts>

注意。struts.xml中有句话是 

!DOCTYPE struts PUBLIC 

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 

"http://struts.apache.org/dtds/struts-2.0.dtd"> 



红色这句可能会报错。解决办法是 将“http://”字样去掉 其它我不知道还有什么方法。有高手知道请指点一二。 



第八步。 

新建result文件 

在WebRoot文件夹下新建一个result.jsp文件 代码例如以下:

  1. ]
  2. <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
  3. <%
  4. String path = request.getContextPath();
  5. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  6. %>
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  8. <html>
  9. <head>
  10. <base href="<%=basePath%>">
  11. <title>My JSP 'result.jsp' starting page</title>
  12. <meta http-equiv="pragma" content="no-cache">
  13. <meta http-equiv="cache-control" content="no-cache">
  14. <meta http-equiv="expires" content="0">
  15. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  16. <meta http-equiv="description" content="This is my page">
  17. <!--
  18. <link rel="stylesheet" type="text/css" href="styles.css">
  19. -->
  20. </head>
  21. <body>
  22. helloworld
  23. username: ${requestScope.username }<br>
  24. password: ${requestScope.password }
  25. </body>
  26. </html>

至此。已经完毕了代码的书写工作。

接下去是公布; 

右键点击struts2这个项目的名称。在菜单中选择myeclipse,在选择add and remove project……就可以,之后将出现图三 

选择project,点击add公布到指定的tomcat就可以、 



最后,打开浏览器。在浏览器 http://localhost:8080/struts2/login.jsp 就可以

struts中的helloword(1)的更多相关文章

  1. Struts中的OGNL和EL表达式笔记

    Struts中的OGNL和EL表达式笔记 OGNL(Object-Graph Navigation Language),可以方便的操作对象属性的表达式语言. 1.#符号的用途 一般有三种方式: 1.1 ...

  2. struts中的数据校验

    1.struts中如何进行数据校验 在每一个Action类中,数据校验一般都写在业务方法中,比如login().register()等.struts提供了数据校验功能.每个继承自ActionSuppo ...

  3. struts中的请求数据自动封装

    Struts 2框架会将表单的参数以同名的方式设置给对应Action的属性中.该工作主要是由Parameters拦截器做的.而该拦截器中已经自动的实现了String到基本数据类型之间的转换工作.在st ...

  4. struts中的常量,action配置中的默认值

    1.struts中Action的开发方式 继承ActionSupport类,这种方法实现的Action可以进行数据校验: 实现Action接口: 不继承任何类,不实现任何接口: 是否继承类或实现接口, ...

  5. Struts中的 saveToken的方法

    Struts中的 saveToken的方法     saveToken防止2次提交的问题 struts有自带的Token(令牌)的机制来解决重复提交(包括后退,刷新等).举例: 假设:假设有一个新增用 ...

  6. Struts中文件的上传与下载

    前面学到的用组件去上传 前台: 1.post表单提交 2.表单类型 multipart/form-data 3.intput type=file 后台: Apach提供的FileUpload组件 核心 ...

  7. Action开发、通配符、路径问题和struts中常量用法

    1.action开发 开发的几种方式 (1).继承自ActionSupport,(如果用struts的数据效验功,能必须必须使用此功能,因为ActionSupport实现了数据效验的接口) publi ...

  8. struts中简单的校验

    Struts中简单的校验 “计应134(实验班) 凌豪” Struts2校验简要说明:struts2中通常情况下,类型转换要在数据校验之前进行.类型转换其实也是基本的服务器端校验,合法数据必然可以通过 ...

  9. Struts中的数据处理的三种方式

    Struts中的数据处理的三种方式: public class DataAction extends ActionSupport{ @Override public String execute() ...

随机推荐

  1. Ubuntu12.04安装JDK6

    因为我们要搭建Android2.3的开发环境,只需要安装JDK6就可以,下面是其下载地址: http://www.oracle.com/technetwork/java/javase/download ...

  2. NET SCADA软件简介

    Scada是一款采用.Net WPF开发的免费组态软件,功能强大,支持服务器客户端方式运行.支持浏览器运行,软件非常小巧,免安装,支持Modbus和OPC通讯协议, 开放构架,支持C#.Net脚本,J ...

  3. BZOJ_1020_[SHOI2008]_安全的航线flight_(计算几何+二分)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1020 给出一条航线(折线),给出\(c\)个陆地(多边形).求航线上距离陆地的最近距离最远的距 ...

  4. NOI2002银河英雄传说

    原先就看过这道题,觉得很复杂. 不知道为什么今天一看觉得好水啊…… 难道这就是并查集的启发式合并? 数组d[i]表示i到其父节点的距离,即中间隔了多少船舰. 数组sum[i]记录以i为根的集合总共有多 ...

  5. easyui资源

    官网地址:http://www.jeasyui.com/index.php(相关文档示例,有demo, tutorial, documentation) 未混淆的源码:http://jquery-ea ...

  6. Azure HDInsight HBase DR解决方案

    Sun wei  Sat, Feb 28 2015 3:07 AM Apache HBase是目前非常流行的NoSQL数据库,通过HDFS+Zookeep+Master+Region Server的架 ...

  7. 【转】iOS 宏(define)与常量(const)的正确使用-- 不错

    原文网址:http://www.jianshu.com/p/f83335e036b5 在iOS开发中,经常用到宏定义,或用const修饰一些数据类型,经常有开发者不知怎么正确使用,导致项目中乱用宏与c ...

  8. EF Code First学习笔记 初识Code First

    Code First是Entity Framework提供的一种新的编程模型.通过Code First我们可以在还没有建立数据库的情况下就开始编码,然后通过代码来生成数据库. 下面通过一个简单的示例来 ...

  9. Visual Studio中的一些较大的文件的作用

    1.sdf 这些是工程中的中间,用于预编译等作用,最终可执行文件是不需要的,默认情况下,删除后重新编译还会生成.如果不需要,在Visual Studio里进入如下设置: 进入"Tools & ...

  10. 可用于Hadoop下的ETL工具——Kettle

    看大家分享了好多hadoop相关的一些内容,我为大家介绍一款ETL工具——Kettle.    Kettle是pentaho公司开源的一款ETL工具,跟hadoop一样,也是java实现,其目的就是做 ...