1、在eclipse中如何复制一个工程作为一个新的工程

在struct.xml中:

<result name="success">/login_sucess.jsp</result>

默认result的那么缺省值就是success,上面的语句等价于

<result >/login_sucess.jsp</result>

2、在上面一节中我们编写的action

package com.weiyuan.test;

/**
* struct2的action可以不继承任何框架的接口
* 1、默认调用的是execute()方法
* */
public class LoginAction {
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;
} public String execute() throws Exception{
System.out.println("execute is called");
System.out.println("execute is called" +username);
System.out.println("execute is called"+password);
if("admin".equals(username)&&"admin".equals(password)){
return "success";
}else{
return "error";
}
} }

没有实现任意的接口,需要自己手动书 public String execute() throws Exception方法,如果写错了就会出现问题,为了解决我们可以让自己编写的ation实现Action这个接口,这个接口默认继承类需要实现 public String execute() throws Exception这个方法,还提供了一些常量

/*
* Copyright (c) 2002-2007 by OpenSymphony
* All rights reserved.
*/
package com.opensymphony.xwork2; /**
* All actions <b>may</b> implement this interface, which exposes the <code>execute()</code> method.
* <p/>
* However, as of XWork 1.1, this is <b>not</b> required and is only here to assist users. You are free to create POJOs
* that honor the same contract defined by this interface without actually implementing the interface.
*/
public interface Action { /**
* The action execution was successful. Show result
* view to the end user.
*/
public static final String SUCCESS = "success"; /**
* The action execution was successful but do not
* show a view. This is useful for actions that are
* handling the view in another fashion like redirect.
*/
public static final String NONE = "none"; /**
* The action execution was a failure.
* Show an error view, possibly asking the
* user to retry entering data.
*/
public static final String ERROR = "error"; /**
* The action execution require more input
* in order to succeed.
* This result is typically used if a form
* handling action has been executed so as
* to provide defaults for a form. The
* form associated with the handler should be
* shown to the end user.
* <p/>
* This result is also used if the given input
* params are invalid, meaning the user
* should try providing input again.
*/
public static final String INPUT = "input"; /** 使用接口可以便于代码编程的规范,定义一些列常量和对应的方法,比如mqtt模块就可以将host admin,等常见定义到接口中,实现和业务的具体分开
package com.weiyuan.test;

import com.opensymphony.xwork2.Action;

/**
* struct2的action可以不继承任何框架的接口
* 1、默认调用的是execute()方法
* */
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;
} public String execute() throws Exception{
System.out.println("execute is called");
System.out.println("execute is called" +username);
System.out.println("execute is called"+password);
if("admin".equals(username)&&"admin".equals(password)){
return "success";
}else{
return "error";
}
} }

     * The action could not execute, since the
* user most was not logged in. The login view
* should be shown.
*/
public static final String LOGIN = "login"; /**
* Where the logic of the action is executed.
*
* @return a string representing the logical result of the execution.
* See constants in this interface for a list of standard result values.
* @throws Exception thrown if a system level exception occurs.
* <b>Note:</b> Application level exceptions should be handled by returning
* an error value, such as <code>Action.ERROR</code>.
*/
public String execute() throws Exception; }

我们的action如下

package com.weiyuan.test;

import com.opensymphony.xwork2.Action;

/**
* struct2的action可以不继承任何框架的接口
* 1、默认调用的是execute()方法
* */
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;
} public String execute() throws Exception{
System.out.println("execute is called");
System.out.println("execute is called" +username);
System.out.println("execute is called"+password);
if("admin".equals(username)&&"admin".equals(password)){
return "success";
}else{
return "error";
}
} } 2、常用配置2:如何在开发阶段,我们修改了struct.xml文件,我们不重启就可以让配置文件的修改有效了有下面的两种方式,注意在正式的运营环境最好不要配置该参数
第一:在工程的src目录下新建文件
struts.properties
配置文件的内容为
struts.configuration.xml.reload=true 第二种方式:在struct.xml的<structs>标签下配置该属性
<?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>
<!-- 当struts.xml配置文件发生修改,会立刻加载,在生产环境下最好不要配置 -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- 需要继承extends="struts-default",否则struct2的拦截器就无法使用 -->
<package name="struct2" extends="struts-default">
<action name="login" class="com.weiyuan.test.LoginAction">
<result name="success">/login_sucess.jsp</result>
<result name="error">/login_error.jsp</result>
</action>
</package> </struts> 3、struct2如何给页面更加有效的错误的提示在struct.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>
<!-- 当struts.xml配置文件发生修改,会立刻加载,在生产环境下最好不要配置 -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- 会提供更加友好的提示信息 -->
<constant name="struts.devMode" value="true"/>
<!-- 需要继承extends="struts-default",否则struct2的拦截器就无法使用 -->
<package name="struct2" extends="struts-default">
<action name="login" class="com.weiyuan.test.LoginAction">
<result name="success">/login_sucess.jsp</result>
<result name="error">/login_error.jsp</result>
</action>
</package> </struts>

总结:

1、<result>标签的name属性,如果不配置,那么缺省值为success


2、Struts2提供了一个Action接口,在Action接口中定义了一些常量和execute方法
我们可以使用该接口,这样开发更规范

3、struts2的常用配置参数
* struts.configuration.xml.reload
--当struts.xml配置文件发生修改,会立刻加载,在生产环境下最好不要配置
* struts.devMode
--会提供更加友好的提示信息

以上参数配置方式有两种:
* 在struts.properties文件中配置
* 在struts.xml配置文件中


 
 

3、struct2的常见配置的更多相关文章

  1. MyEclipse常见配置及调试

    常见配置 1.配置workspace ----- 建议不要采用含有空格和中文目录 所有代码保存workspace空间中2.新建工程时,设置工程需要jre环境MyEclipse提供多种内置layout ...

  2. Httpd2.2常见配置及功能

    Httpd 2.2常见配置 要配置http服务的配置文件,先备份一下,养成良好习惯,如果误操作导致http服务起不来,就可以将备份的主配置文件重新覆盖一下 httpd配置文件的组成:有三大部分组成,其 ...

  3. Spring Boot常见配置及错误

    一.SpringBoot常见配置 (1)SpingBoot与MyBatis集成时跟踪SQL语句 log4j: logger: java: sql: ResultSet: TRACE (2)日志跟踪 d ...

  4. httpd常见配置

    httpd常见配置 配置文件 /etc/httpd/conf/httpd.conf    主配置文件 /etc/httpd/conf.d/*.conf  辅助配置文件 配置文件语法检查及重新加载配置文 ...

  5. Struts2常见配置(草稿)

    Struts2框架配置文件加载的顺序(了解加载配置文件的顺序,重点掌握struts.xml配置文件) 1.Struts2框架的核心是StrutsPrepareAndExecuteFilter过滤器,该 ...

  6. Java-JVM调优常见配置举例

    常见配置举例 堆大小设置JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制:系统的可用虚拟内存限制:系统的可用物理内存限制.32位系统 下,一般限制在1.5G~ ...

  7. Redis系列四 Redis常见配置

    redis.conf常见配置 参数说明redis.conf 配置项说明如下:1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程  daemonize no2. ...

  8. Mybatis常见配置错误总结

    Mybatis常见配置错误总结 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionF ...

  9. web.xml的常见配置

    web.xml的常见配置 <!-- 配置全局的编码过滤器 --> <filter> <description>编码过滤器</description> & ...

随机推荐

  1. linux:基本指令

    指令标准格式 指令主体 [选项][操作对象] 基础指令 ls 1.ls 列出当前工作目录下的所有文件/文件夹的名称 2.ls  路径 列出指定路径下的所有文件/文件夹的名称 路径: 1.相对路径 会用 ...

  2. php CURL 发送请求封装

    cURL可以使用URL的语法模拟浏览器来传输数据,因为它是模拟浏览器,因此它同样支持多种协议,FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以及 ...

  3. Flutter,webview里面实现上传和下载的功能

    前提:Flutter 与 webview(vue) 一起开发的项目 开始的时候并没有想到什么移动端的,所以上传就用input,下载就用iframe来实现,然而真机实测的时候,input那个方法IOS支 ...

  4. jchdl - GSL实例 - Mul(无符号数的乘法)

      这里实现最原始的阵列乘法,逐位相乘然后加到一起.   参考链接 https://github.com/wjcdx/jchdl/blob/edcc3e098d4f1cb21677e86e87a114 ...

  5. IntelliJ IDEA连接不上数据库 (Connection to testdb@localhost failed. [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.)

    问题提示为: 原因:MySQL数据库版本为8.0以上,需要在URL加上时区,即加上?serverTimezone=GMT 成功后为:

  6. Java实现 LeetCode 745 前缀和后缀搜索(使用Hash代替字典树)

    745. 前缀和后缀搜索 给定多个 words,words[i] 的权重为 i . 设计一个类 WordFilter 实现函数WordFilter.f(String prefix, String su ...

  7. Java实现 蓝桥杯 算法训练 Pollution Solution

    试题 算法训练 Pollution Solution 问题描述 作为水污染管理部门的一名雇员,你需要监控那些被有意无意倒入河流.湖泊和海洋的污染物.你的其中一项工作就是估计污染物对不同的水生态系统(珊 ...

  8. 第十届蓝桥杯JavaC组省赛真题

    试题 A: 求和 本题总分:5 分 [问题描述] 小明对数位中含有 2.0.1.9 的数字很感兴趣,在 1 到 40 中这样的数包 括 1.2.9.10 至 32.39 和 40,共 28 个,他们的 ...

  9. Java实现 LeetCode 396 旋转函数

    396. 旋转函数 给定一个长度为 n 的整数数组 A . 假设 Bk 是数组 A 顺时针旋转 k 个位置后的数组,我们定义 A 的"旋转函数" F 为: F(k) = 0 * B ...

  10. Java实现选号码

    选号码 Description CF打算换个手机号码,但是他去营业厅选号码的时候却把移动的客服小姐烦得不行,因为他太挑三捡四啦. 对于一个手机号的后六位数字(前面五位他就无所谓了)CF有很严格的要求, ...