配置 Struts2 Hello World
http://javaweb.group.iteye.com/group/wiki/1505-struts2-under-helloworld---how-to-make-the-first-of-the-running-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
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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 'login.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>
<form action="login.action" method="post">
username: <input name="username" type="text"><br>
password: <input name="password" type="password"><br> <input type="submit" value="submit">
</form>
</body>
</html>
第五步:
修改WEB-INF下的web.xml文件
代码如下
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <filter>
<filter-name>struts2</filter-name>
<!-- 控制器 -->
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<!-- 任何请求均有过滤器 -->
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
第六步:
新建action
在src目录下新建包com.test.action
在包中新建一个action代码如下
LoginAction.java
package com.test.action;
public class LoginAction
{
//getter和setter方法 就是根据这里的方法名来匹配客户端的信息
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute() throws Exception
{
return "success";
}
//对应表单上的
private String username;
private String password;
}
第七步:
struts配置文件
在src目录下新建一个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="struts2" extends="struts-default">
<action name="login" class="com.test.action.LoginAction">
<!-- result没有名字是默认的success -->
<result name="success">/result.jsp</result>
</action>
</package>
</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文件 代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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 'result.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>
helloworld
username: ${requestScope.username }<br>
password: ${requestScope.password }
</body>
</html>
配置 Struts2 Hello World的更多相关文章
- 配置struts2+spring,springmvc
Struts2+Spring整合 一.spring负责注入,struts2负责它自己的工作.这样不是很符合spring作为ioc容器的全部功能,不推荐. 二.spring负责全部bean和struts ...
- Eclipse配置Struts2.x
问了我同学现在JavaWeb主流框架是哪些.他说基本框架是SSH,struts2+spring+hibernate,流行的是SSM,springmvc+spring+mybatis,原本计划学下Str ...
- (原创)超详细一步一步在eclipse中配置Struts2环境,无基础也能看懂
(原创)超详细一步一步在eclipse中配置Struts2环境,无基础也能看懂 1. 在官网https://struts.apache.org下载Struts2,建议下载2.3系列版本.从图中可以看出 ...
- 在web.xml中配置struts2拦截器
<!-- 配置Struts2的核心的过滤器 --> <filter> <filter-name>struts2</filter-name> <fi ...
- MyEclipse如何配置Struts2源码的框架压缩包
1.MyEclipse如何配置Struts2源码的框架压缩包 如本机的Struts2框架压缩包路径为:D:\MyEclipseUserLibraries\struts\struts-2.3.15.3- ...
- eclipse中配置struts2出现There is no Action mapped for namespace [/] and action name [Login] associated wi
下午在eclipse中配置struts2时报: There is no Action mapped for namespace [/] and action name [Login] associat ...
- Struts2学习第2天--Struts2的Servlet的API的访问 Struts2的结果页面的配置 Struts2的数据的封装(包括复杂类型)
启动后访问jsp 输入姓名密码: 提交后跳转打action 打印: 修改类: 配置同上 结果同上. 实现这俩接口 就得到了 以上代码附上: struts.xml: <?xml version=& ...
- 配置Struts2及Struts2访问servlet api的方式
Struts2的起源与背景 在很长的一段时间内,在所有的MVC框架中,Struts1处于绝对的统治地位,无论是从市场的普及范围,还是具体的使用者数量. 其他MVC框架都无 法与其相比,作为一一款优秀的 ...
- 给 ecplise 配置struts2配置环境
下面介绍在Eclipse中配置Struts2的过程: 一.下载Struts2,因为Struts2是开源的,百度或者google一下就可以找到下载地址.我下载的是struts-2.3.1.2版本 的,解 ...
- 在Eclipse里面配置Struts2
下面介绍在Eclipse里面配置Struts2 下载Struts2的压缩包 我下载的是2.3.32版本 解压之后如图所示 apps目录:Struts2的范例 docs目录:Struts2的文档 lib ...
随机推荐
- 基于新浪sae使用php生成图片发布图文微博
1.生成图片的代码: <?php header ("Content-type: image/png"); mb_internal_encoding("UTF-8&q ...
- android学习日记06--SurfaceView视图
一.API关SurfaceView的介绍 SurfaceView是视图(View)的继承类,这个视图里内嵌了一个专门用于绘制的Surface.你可以控制这个Surface的格式和尺寸.Surfacev ...
- tcp_tw_recycle和tcp_timestamps的文章汇总
临近年关,人会变得浮躁,期间写的代码可谓乱七八糟.不过出来混始终是要还的,这不最近就发现一个PHP脚本时常连不上服务器. 遇到这类问题,我习惯于先用strace命令跟踪了一下看看: shell ...
- C如何获取文件夹下所有文件
http://baike.baidu.com/view/1186290.htm?fr=aladdin 使用io.h中的_findfirst,_findnext,_findclose,_finddata ...
- 进程环境之C程序的存储空间布局
从历史上讲,C程序一直由下面几部分组成: 正文段.这是由CPU执行的机器指令部分.通常,正文段是可共享的,所以即使是频繁执行的程序(如文本编辑器.C编译器和shell等)在存储器中也只需有一个副本,另 ...
- win10.10 激活
最近几天一直有同学来找我说,为什么用密钥或kms神龙版都无法激活win8/8.1.win10,于是我就让这些同学给我截图,结果他们激活出错的信息基本都一样,都是错误:“0XC004F074 软件授权服 ...
- iOS app 上架的流程与注意点
这里整理了两个关于苹果应用商店上架方面的资料: 一个是app上架的流程,里面包含各个环节的截图,比较详细. 流程介绍链接 (提取码:52a4) 第二个是app上架的一些注意点,这里面主要说的是上架 ...
- c++与c不太相同的一些地方2
1.一般全局变量放到cpp 文件里面,而不是.h 里面.要不然容易乱套,这个乱几次就好了,先记住这样一种编码规范. 以为大家都引入就比较麻烦,但是实现起来就只有cpp里面才有.毕竟.h是要被包含的文件 ...
- LVM的添加与删除
#############################创建 fdisk -l查看分区情况 fdisk /dev/xvdb pvcreate /dev/xvdb1 vgextend VolGroup ...
- php实现比较两个字符串日期大小的方法
<?php function dateBDate($date1, $date2) { // 日期1是否大于日期2 $month1 = date("m", strtotime ...