struts2笔记(一)HelloWorld
来源:互联网 发布:用阿里云搭建ip代理 编辑:程序博客网 时间:2024/05/22 18:24
最近在看李刚的Struts2.1权威指南,按照书上内容,自己写了一个HelloWorld,但是发现总是出现No result defined for action and result error这个问题,使用网上介绍的各种方法都没有解决这个问题,后来我自己手动添加了struts2.3的jar包(原来用的是myeclipse添加的struts2.1)。问题得到了解决,但是tomcat会出现如下警告
下面给出HelloWorld的新建过程,以及以上问题的解决方法。
1.首先新建一个Web工程。
2.下载struts,并将以下包放到工程的lib文件夹下面,并引入工程
1)xwork-core-xxx
2)struts2-core-xxx
3)ognl-2.x.x
4)freemarker-2.x.xx
5)commons-io-1.x.x
6)commons-fileupload-1.x.x
3.在编辑WEB-INF下编辑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"> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> <!-- 定义Struts2 的核心控制器:2.3版本用这个控制器 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <!-- filter用来初始化Struts2并且处理所有的HTTP请求 --> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
上文红色部分为struts2.3的核心控制器,这和2.1版本是不同的,改写成这个后就不会出现上文的WARNING了。4.在源文件目录下新建一个struts.xml
并编辑
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts> <constant name="struts.devMode" value="true"></constant> <constant name="struts.i18n.encoding" value="utf-8"></constant> <package name="fang" extends="struts-default"><action name="login" class="com.fang.login.action.LoginAction"> <result name="error">/error.jsp</result> <result name="success">/welcome.jsp</result></action></package></struts>5.编写LoginAction.java
package com.fang.login.action;import com.opensymphony.xwork2.Action;public class LoginAction implements Action{private String username;private String password;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;}//处理用户请求的execute方法public String execute() throws Exception{if(getUsername().equals("fangjava")&&getPassword().equals("fang")){return SUCCESS;}else{return ERROR;}}}6.编写相应的jsp文件。
小结:在struts2.1下面出现No result defined for action and result error问题的原因仍然没有找到,自己也没有跟代码跟到框架里,所以分析不出原因。
0 0
- struts2笔记(一)HelloWorld
- struts2自学笔记一(HelloWorld)
- struts2 学习一 HelloWorld
- Struts2(一)-HelloWorld
- OSGI笔记(一)HelloWorld
- OSGI笔记(一)HelloWorld
- OSGI笔记(一)HelloWorld
- OSGI笔记(一)HelloWorld
- Struts2(一)-Struts2之HelloWorld
- Struts2.1笔记(二):Struts2下的HelloWorld
- 传智Struts2笔记(二)第一个Struts2应用--HelloWorld
- Struts2再学习一 HelloWorld
- Struts2笔记(一)
- struts2笔记(一)
- struts2笔记(一)
- Vala学习笔记(一) - HelloWorld!
- Memcached 学习笔记(一)安装 & helloworld
- window程序设计笔记(一)helloworld
- 《学习openCV》例程解析 ex_9_3_ex(codeBook + 连通净化)
- 如何正确的做好网站分析?
- JQuery插件 之 jqgrid(一)
- Jquery实现的Tabs
- 类图之间的关系
- struts2笔记(一)HelloWorld
- FFMPeg代码分析:AVPacket结构体和av_read_frame函数
- cocos2dx里的sqlite数据库加密,且不影响sqlite工具打开阅读数据
- C++下遍历文件夹
- 深度探索C++对象模型:4.Function语意学
- Linux系统备份
- Android ListView 去除各种颜色问题
- 基于HTML5和Tomcat WebSocketServlet的聊天室简单实现
- 【黑马程序员】Java基础加强16:JDK1.5泛型