SBF胜博发娱乐老虎机ajax返回值中,在首位会出现一些莫名其妙的空行

( SBF胜博发娱乐老虎机 )

我使用的是wordpress,不知道为什么返回的时候会有一些空行出现。

Jquery

$.ajax({
        type:'post',
        url:localcurrent.ajax_url,
        data:favorite_data,
        success:function(response){
            alert(response);
        }
    });

PHP

function favorite_post(){
    $post_id = $_POST["post_id"];
    $user_id = get_current_user_id();
    $favorite = favorite_get($post_id,1);
    //  判断用户是否已经收藏该文章
    if(!in_array($user_id, $favorite)){
        //  用户未收藏此项,要添加收藏
        favorite_add($user_id,$post_id);
        echo 'add';
        exit;
    }else{
        //  用户已收藏此项,要移除收藏
        favorite_del($user_id,$post_id);
        echo 'remove';
        exit;
    }
    echo 'error';
    exit;
}
add_action('wp_ajax_favorite_post', 'favorite_post');

我觉得有两种情况:
1、就是楼上说的,PHP 模板里面的一些东西。
2、返回的数据带BOM 的utf-8格式的文本,也会出现这种情况。

是不是php的模板文件顶部的 删除了php标签啥的? 我之前也是这样 ,排查了好久,后来才发现是我删除了模板文件顶部的一些东西

用浏览器抓包看看

(看完/读完)这篇文章有何感想! SBF胜博发娱乐老虎机的分享…

胜博发游戏官网php正则表达式匹配一段中文,中间有换行,空白,应该怎么写?

( 胜博发游戏官网 )

1、举个例子:

<div class="con">
    <p>
        小学生手册:<br />
        1、好好学习;<br />
        2、天天向上;<br />
    </p>
</div>

要把中间p标签中的内容抓出来,正则表达式应该怎么写?

$tmp = '<div class="con">
    <p>
        小学生手册:<br />
        1、好好学习;<br />
        2、天天向上;<br />
    </p>
</div>';

preg_match('/<p>(.*?)<\/p>/s', $tmp, $ret);

echo $ret[1];

请参看 PCRE_MULTILINE 模式修饰符 m
http://php.net/manual/zh/reference.pcre.pattern.modifiers.php

(看完/读完)这篇文章有何感想! 胜博发游戏官网的分享…

胜博发游戏官网php爬虫ajax请求地址怎么获取?

( 胜博发游戏官网 )

用php爬虫抓取网页,网页上有个信息需要登录后才显示在页面中,是一个ajax请求的信息。按F12找到了这个ajax请求地址,javascript生成的,那么,如何获取这个地址呢?

补充:
ajax请求的jquery代码:

$(document).ready(function(){
    var id="100";
    var tsTimeStamp= new Date().getTime();
    $.get("http://www.xxxx.com/extra/ajax_contact.php", { "id": id,"time":tsTimeStamp,"act":"locations_contact"},
        function (data,textStatus)
         {            
            $("#locations_contact").html(data);
         }
    );
})

按F12在那个框里面显示的ajax请求地址:ajax_contact.php?id=100&time=1442484035051&act=locations_contact
把上面这个地址在新窗口打开显示的完整地址:http://www.xxxx.com/extra/ajax_contact.php?id=100&time=1442484035051&act=locations_contact

每个页面id不一样,怎么把这个地址取到?

分析js, 找js是怎么拼这个地址的, 用的哪些变量, 这个变量的值又是哪里来的,然后自己组装.


<?php

$html = '';//这里为抓到的HTML内容

preg_match('/var id="(\d+)";/', $html, $result);//匹配出来 id的值,

//接下来你就可以用取到的id(保存在变量 $result 中), 接到你抓到的那个URL中发请求了.

(看完/读完)这篇文章有何感想! 胜博发游戏官网的分享…

胜博发游戏官网开发一个简单的PHP框架,有哪些安全问题需要注意?

( 胜博发游戏官网 )

自认为,做一个最简单的PHP mvc框架,用URL路由函数匹配URL中的controller和method的名字,如果method_exists则new该controller再用call_user_func_array执行该method,否则引入error的controller,每个controller中可以require引入model,再require引入tpl,这是我做一个最简单的PHP框架的思路,那这里面需要注意哪些安全问题呢?

  • 路径问题,不能通过url调用应用外部文件比如/etc/passwd

  • 数据过滤,永远不要信任用户的任何输入。输入的所有数据使用htmlspecialchars过滤后入库。

  • 数据库,使用PDO代替mysql_xxxx,使用参数绑定处理外部数据(如果数据库只使用mysql也可使用mysqli扩展)

关于 call_user_func_array 的安全问题,之前drupal中过招。

http://blog.knownsec.com/2014/10/drupal__callback_nightmare/

require 可能产生文件包含漏洞。

http://www.neatstudio.com/show-1123-1.shtml

(看完/读完)这篇文章有何感想! 胜博发游戏官网的分享…

SBF胜博发娱乐老虎机php抓取页面后,有什么好的方式解析dom提取数据?

( SBF胜博发娱乐老虎机 )

php抓取页面后,有什么好的方式解析dom提取数据?

phpQuery

让php处理html代码像jQuery一样方便

xpath

(看完/读完)这篇文章有何感想! SBF胜博发娱乐老虎机的分享…

sbf胜博发娱乐城有没有人使用过Requests for PHP?

( sbf胜博发娱乐城 )

POST http://10.18.32.78/nps/login.action HTTP/1.1
Host: 10.18.32.78
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://10.18.32.78/nps/login_view.action;jsessionid=9DC8C0E7A12FF26279DB8123088C6DC6
Cookie: JSESSIONID=9DC8C0E7A12FF26279DB8123088C6DC6
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 34

userName=092312123&password=123456

上面是用fiddler抓到的
下面是我的代码

require './Requests-1.6.0/library/Requests.php';
Requests::register_autoloader();

$url = 'http://10.18.32.78/nps/login.action';
$headers = array(
    'Host' => '10.18.32.78',
    'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0',
    'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language' => 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
    'Accept-Encoding' => 'gzip, deflate',
    'Referer' => 'http://10.18.32.78/nps/login_view.action;jsessionid=9DC8C0E7A12FF26279DB8123088C6DC6',
    'Cookie' => 'JSESSIONID=9DC8C0E7A12FF26279DB8123088C6DC6',
    'Connection' => 'keep-alive',
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Content-Length' => '34'
);

//var_dump($headers);
$options = array();
$data = array(
    ''=>'userName=092312123&password=123456'
);

// Now let's make a request!
$request = Requests::post($url, $headers, $data);

下面是运行的结果

string '
<html>
<head>
    <title>东软睿道睿鼎教学实训平台 - </title>
    <link href="/nps/css/default.css" rel="stylesheet" type="text/css">
    <script language="javascript" src="/nps/js/jquery.js"></script>
    <script language="javascript" src="/nps/js/jquery.selectboxes.js"></script>
    <script language="javascript" src="/nps/js/common.js"></script>
    <script language="javascript" src="/nps/js/init.js"></script>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    
</head>
<body >
<s'... (length=2212)

请问为什么显示的不全呢

这咋就显示不全呢? 直接echo 不要var_dump

(看完/读完)这篇文章有何感想! sbf胜博发娱乐城的分享…

SBF胜博发娱乐老虎机微信支付native方式没有收到异步通知

( SBF胜博发娱乐老虎机 )

请教一个问题,就是微信支付的PHP SDK
我想在网页中扫描微信二维码支付,下载了官方的SDK
运行了example 中的native.php
通过模式二来扫码支付

$input->SetNotify_url("http://127.0.0.1/wxpay/example/notify.php”);

但是我发现支付成功了,可是微信没有向我设置的notify发异步请求,请问该如何解决,还是我的逻辑错误?

兄弟,微信支付回调地址必须是公网可访问的地址,是微信支付的服务器访问不到你的本地环境地址。

(看完/读完)这篇文章有何感想! SBF胜博发娱乐老虎机的分享…

SBF胜博发娱乐老虎机lavarel php aritisan migrate报错

( SBF胜博发娱乐老虎机 )

PHP Notice:  Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' in /var/www/billstatistics/config/app.php on line 83

Notice: Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' in /var/www/billstatistics/config/app.php on line 83


                         
  [PDOException]         
  could not find driver  
                    
                    
                    

local.ERROR: exception ‘PDOException’ with message ‘could not find driver’

什么原因,我看了php扩展有pdo_mysql

这样报错90%是没有正确加载pdo啊,不用怀疑系统给你的报错。

注:命令行和服务器的php扩展加载是不一样的

第二,敢问题主用的laravel版本是?

第三,貌似你的laravel还需要MCRYPT的支持?

以后有什么laravel相关的问题,可以到这里laravist来交流一下,我会尽力帮你解决

sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt

//php.ini
extension=mcrypt.so

sudo service apache2 restart

(看完/读完)这篇文章有何感想! SBF胜博发娱乐老虎机的分享…

sbf胜博发娱乐城Yii2框架中,有必要再分离service层么?

( sbf胜博发娱乐城 )

目前的项目中,service层,就是使用静态方法调用,方法内再实例化ar model

而Yii2自动生成的模板中,是直接在model中使用ar model。

两者没有多大的区别,那分离出service层的意义是什么?

在简单的系统里面,分层是这样的

controller <-> model <-> storage(sql、nosql、cache)

所有的业务逻辑都在model上

现在讨论一个常见的场景,用户下订单要买点东西,这个业务逻辑涉及到的model类有User(用户)、Order(订单)、Goods(商品)

那么下订单这个事情是放到User还是Order上?无论放在User还是Order上,这个业务逻辑都需要多个model类的参与

这种需求在系统里面越来越多,你就会发现你总有那么几个model在不断的膨胀,这些model之间甚至产生了网状的相互依赖关系

需求越复杂,你越容易陷入这种混乱的局面

service层的作用就是把这些需要多个model参与的复杂业务逻辑单独封装出来,这些model之间不再发生直接的依赖,而是在service层内协同完成逻辑

service层的第一个目的其实就是对model层进行解耦

业界对前面提到的那种不断膨胀的model称为“充血模型”,起初对充血模型进行反思的一种解决方案就是“贫血模型”,model里面尽量少放点逻辑,把这些逻辑都移动到controller层面去处理,在controller里面调用多个model完成业务逻辑,也达到了对model间解耦的作用

但问题就是,业务逻辑都放到controller层面了,如果其它的controller也需要相同的业务逻辑时,只能在controller里面调用其它的controller,这样做既不方便又麻烦

所以后来还是把这种解耦单独放一层,叫service,现在分层就变成这样

controller <-> service <-> model <-> storage

service层的第二个作用就是重用

差不多就是这样

简单粗暴的总结来说,如果你的某个业务逻辑,需要用到多个model,就放到service层里面去,如果只是这个model自己的事,跟其它的model没有任何关系,就放到model里面就好。

如果你的系统本来就很小,业务逻辑也超级简单,也不存在长期演进迭代的需求,随你怎么高兴怎么写都行。

取决于model层是否够乱

该不该分离出新的层,有无service层都有各自的好处,没有优劣

乱了才拆,不乱不管,就看合适不合适

如果真的很乱,非拆分不可,想必题主也不会再提问,所以推测现在是刚开始乱

如果真是这样,其实这就是开始了,推荐现在就拆

分层永远是处理复杂业务的有效手段(一般项目三层,复杂的项目回到四层、五层)。

在面向OO的系统里,service就是biz manager,在面向过程的系统里service就是TS脚本。

AR Model里面当然可以放业务代码,但仅限于操作这个model自身(如果使用了repository则也不能操作同类型别的model,而应该在repository中操作某一类models),不对其他类型model产生依赖。

业务manager(也就是所谓的service)则根据业务,处理不同类型model或者repository之间的关系。

业务更加复杂时可以抽出子系统的facade门面,处理不同业务manager调用顺序。

最后在controller里调用它们(对, controller也可以认为是一个facade)。

我接触过的项目都在这几层里面,再复杂也就到facade。小项目当然直接扔到model里,,随着业务不断复杂,我们要做的只是不断重构而已。

(看完/读完)这篇文章有何感想! sbf胜博发娱乐城的分享…

sbf胜博发娱乐城php怎么将二维数组键名相同的元素转为新的数组?不用for,foreach循环

( sbf胜博发娱乐城 )

如图所示是一个二维数组[别纠结,为了方便我将其转为了json], 其中type只有两个值1和2,
现在需要将type=1的元素转到$new数组中,type=2的转到$old数组中。

除了用循环还有什么方法没?

附上json:

[{"id":"10","type":"1","cpu":"Intel Xeon E3-1241v3","cores":"4","ram":"16","hard_drive":"1TB SATA","port_speed":"100Mbps","transfer":"20TB","ipmi_kvm":"Y","price":"148","price1":"142","price2":"135","price3":"127","price4":"118","add_time":"0000-00-00 00:00:00","edit_time":"0000-00-00 00:00:00","ip":null},{"id":"11","type":"1","cpu":"Intel Xeon E5-1650v2","cores":"6","ram":"16","hard_drive":"1TB SATA","port_speed":"100Mbps","transfer":"20TB","ipmi_kvm":"Y","price":"198","price1":"190","price2":"180","price3":"170","price4":"158","add_time":"0000-00-00 00:00:00","edit_time":"0000-00-00 00:00:00","ip":null},{"id":"12","type":"1","cpu":"Dual Intel Xeon E5-2630v2","cores":"12","ram":"64","hard_drive":"1TB SATA","port_speed":"100Mbps","transfer":"20TB","ipmi_kvm":"Y","price":"348","price1":"334","price2":"317","price3":"299","price4":"278","add_time":"0000-00-00 00:00:00","edit_time":"0000-00-00 00:00:00","ip":null},{"id":"4","type":"2","cpu":"Intel Core i3-2100T","cores":"2","ram":"16","hard_drive":"1TB SATA","port_speed":"100Mbps","transfer":"20TB","ipmi_kvm":"Y","price":"68","price1":"65","price2":"61","price3":"56","price4":"51","add_time":"2015-09-16 16:36:39","edit_time":"2015-09-16 16:36:42","ip":"127.0.0.1"},{"id":"5","type":"2","cpu":"Intel Xeon X3470","cores":"4","ram":"16","hard_drive":"1TB SATA","port_speed":"100Mbps","transfer":"20TB","ipmi_kvm":"Y","price":"78","price1":"75","price2":"70","price3":"65","price4":"59","add_time":"2015-09-16 16:37:24","edit_time":"2015-09-16 16:37:27","ip":"127.0.0.1"},{"id":"6","type":"2","cpu":"Intel Core i5-2400","cores":"4","ram":"16","hard_drive":"1TB SATA","port_speed":"100Mbps","transfer":"20TB","ipmi_kvm":"Y","price":"88","price1":"84","price2":"79","price3":"73","price4":"66","add_time":"2015-09-16 16:38:14","edit_time":"2015-09-16 16:38:16","ip":"127.0.0.1"},{"id":"7","type":"2","cpu":"Intel Core i7-2600","cores":"4","ram":"16","hard_drive":"1TB SATA","port_speed":"100Mbps","transfer":"20TB","ipmi_kvm":"Y","price":"98","price1":"94","price2":"88","price3":"81","price4":"74","add_time":"2015-09-16 16:40:02","edit_time":"2015-09-16 16:40:04","ip":"127.0.0.1"},{"id":"8","type":"2","cpu":"Intel Core i7-3770S","cores":"4","ram":"16","hard_drive":"1TB SATA","port_speed":"100Mbps","transfer":"20TB","ipmi_kvm":"Y","price":"118","price1":"113","price2":"106","price3":"98","price4":"89","add_time":"2015-09-16 16:40:50","edit_time":"2015-09-16 16:40:52","ip":"127.0.0.1"},{"id":"9","type":"2","cpu":"Dual Intel Xeon X5650","cores":"12","ram":"64","hard_drive":"1TB SATA","port_speed":"100Mbps","transfer":"20TB","ipmi_kvm":"Y","price":"318","price1":"305","price2":"286","price3":"264","price4":"239","add_time":"2015-09-16 16:42:00","edit_time":"2015-09-16 16:42:02","ip":"127.0.0.1"}]

/*
 * 好吧。不知道是不是你需要的。还有想说一句,有这个必要吗?
 * */
$b =
    array(
        array('type' => 1, 'name' => 'lisi'),
        array('type' => 2, 'name' => 'lisi'),
        array('type' => 1, 'name' => 'lisi'),
        array('type' => 1, 'name' => 'lisi'),
    );

$newArray = array();

print_r(array_filter($b,'filtertype'));

echo '<br>';

print_r(array_filter($b,'filtertypetwo'));

function filtertype($var)
{
    return $var['type'] ==1;
}

function filtertypetwo($var)
{
    return $var['type'] ==2;
}

array_column — 返回数组中指定的一列 (注意版本要求。PHP 5 >= 5.5.0)

<?php
 $records  = array(
    array(
         'id'  =>  2135 ,
         'first_name'  =>  'John' ,
         'last_name'  =>  'Doe' ,
    ),
    array(
         'id'  =>  3245 ,
         'first_name'  =>  'Sally' ,
         'last_name'  =>  'Smith' ,
    ),
    array(
         'id'  =>  5342 ,
         'first_name'  =>  'Jane' ,
         'last_name'  =>  'Jones' ,
    ),
    array(
         'id'  =>  5623 ,
         'first_name'  =>  'Peter' ,
         'last_name'  =>  'Doe' ,
    )
);
 
 $first_names  =  array_column ( $records ,  'first_name' );
 print_r ( $first_names );
 ?>   

以上例程会输出:

Array
(
    [0] => John
    [1] => Sally
    [2] => Jane
    [3] => Peter
)

除了不循环,我想不到别的法子,关注一下,等高人回答。

array_map(function($v){
    if($v['type'] == 1){
        $GLOBALS['new'][] = $v;
    }else if($v['type'] == 2){
        $GLOBALS['old'][] = $v;
    } 
}, json_decode($json, true));

$arr = [];//给的数组
$result = array_map(function($v){
    if($v['type'] == 1) return $v;
},$arr);
var_dump($result);

$gang = array(
    array('id'=>1,'term_id'=>2,'name'=>'哈哈'),
    array('id'=>2,'term_id'=>1,'name'=>'嘻嘻'),
    array('id'=>1,'term_id'=>2,'name'=>'哈哈'),
    array('id'=>1,'term_id'=>3,'name'=>'哈哈'),
    array('id'=>1,'term_id'=>1,'name'=>'哈哈'),
    array('id'=>1,'term_id'=>4,'name'=>'哈哈'),
    array('id'=>1,'term_id'=>3,'name'=>'哈哈'),
    array('id'=>1,'term_id'=>2,'name'=>'哈哈'),
);
foreach ($gang as $vo) {
    $haha[$vo['term_id']][] = $vo;
}
var_dump($haha);
$data = array();
$a = array_map(function($v){ $GLOBALS['data'][$v['term_id']][] = $v;return $v;},$gang);
var_dump($GLOBALS['data']);

闭包中使用GLOBALS即可

(看完/读完)这篇文章有何感想! sbf胜博发娱乐城的分享…

胜博发游戏官网php爬虫拿到ajax请求地址应该放在哪里执行?

( 胜博发游戏官网 )

用的phpcrawl框架,
第1步是设置开始地址;
第2步是设置要下载的内容类型:text/html;
第3步是用正则表达式设置要扩展的url规则;
第4步就是开始抓取,抓取符合第3步url规则的网址的内容。
第5步是用正则表达式或dom解析工具解析自己需要的内容。

问题是:
有些内容是ajax请求,请求地址是javascript写的,已经拼接好了。那么,这个地址应该怎么样才可以让这个爬虫去执行?放在第3步的扩展地址不行,因为是自己拼接的,源代码中没有这个地址,匹配不到。

直接使用拼接后的地址,然后查看该AJAX是GET还是POST请求,设置好参数后再做一次curl请求,然后再解析数据。

(看完/读完)这篇文章有何感想! 胜博发游戏官网的分享…

sbf胜博发娱乐城任务系统统计每个员工所占用任务的比例

( sbf胜博发娱乐城 )

自己搭建了一个任务系统 现在需要做一个 领导分配任务后在任务过程中能查看员工所占任务比例。目前的一个思路 使用 Google chart类 ,谁有比较简单快捷的方法呢!

直接显示百分比岂不是更快更好?
如果想要图形化,直接用excel嘛~

(看完/读完)这篇文章有何感想! sbf胜博发娱乐城的分享…

SBF胜博发娱乐老虎机Mysql如何实现在插入数据时更新其中一个字段?

( SBF胜博发娱乐老虎机 )

我的sql语句如图,如何在insert的时候更新其中的project_id字段呢?

直接给你个例子,相信你能看懂,
insert into users (id,username,password) select null,username,'3333' from users where id=1

ON DUPLICATE KEY UPDATE 语法,这个要配合唯一索引使用

先插入insert 如果成功则 返回自增ID,再执行update 这样可以啊,执行2条SQL就行

这是要写触发器么。。。

(看完/读完)这篇文章有何感想! SBF胜博发娱乐老虎机的分享…

胜博发游戏官网微信公众平台 多客服 客户如何主动更换客服

( 胜博发游戏官网 )

微信公众号中有几个客服列表,刚开始客户选择客服1,聊了几分钟后,客户想主动更换成客服2.请问这样该如何操作。
貌似微信第一次选择客服后就不在去开发者的代码逻辑中判断了,直接从微信的服务器发送信息到相应的客服客户端。

(看完/读完)这篇文章有何感想! 胜博发游戏官网的分享…

SBF胜博发娱乐老虎机struts拦截器连登录界面也一起拦截了,无法登录

( SBF胜博发娱乐老虎机 )

1.最近在学习struts2的拦截器。配置了一个登陆的拦截器。可是在输入登录信息后,打断点发现,直接进入拦截器,未先进入相应的Action中将登录信息保存在session中,导致拦截器一直给跳转到登录页。
拦截器配置如下:

public class AuthInterceptor extends AbstractInterceptor {
public String intercept(ActionInvocation actionInvocation) throws Exception{
    //1.获取访问的url
    String url = actionInvocation.getProxy().getActionName();
    //2.从session中获取相应的登录用户和是否是管理员
    String username = (String) ActionContext.getContext().getSession().get("loginUser");
    Boolean isAmin = (Boolean) ActionContext.getContext().getSession().get("isAdmin");
    //3.根据地址判断是否已经可以授权访问
    if(url.startsWith("admin_")){
        if(username == null || "".equals(username.trim())){
            return "loginInput";
        }
        if(isAmin == null || !isAmin){
            return "error";
        }
    }else{
        if(username == null || "".equals(username.trim())){
            return "loginInput";
        }
    }
    return actionInvocation.invoke();
    }
   }
   

struts.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<package name="default" namespace="/" extends="struts-default">
    <interceptors>
        <!--创建了一个拦截器的配置,但是此时配置并没有生效,需要在action中配置才能生效-->

        <interceptor name="authInterceptor" class="com.van.interceptor.AuthInterceptor"></interceptor>
        <!--一个拦截器栈中可以加入多个拦截器-->
        <interceptor-stack name="authStack">
            <interceptor-ref name="defaultStack"></interceptor-ref>
            <interceptor-ref name="authInterceptor"></interceptor-ref>
        </interceptor-stack>
    </interceptors>
    <!--全局结果集:公共的结果集,所有action只要找到相应的返回值就会来对应全局结果集-->
    <global-results>
        <result name="error">/WEB-INF/inc/error.jsp</result>
        <result name="loginInput">/WEB-INF/Login/input.jsp</result>
    </global-results>
    <action name="*_*_*" class="com.van.action.{2}Action" method="{3}">
        <interceptor-ref name="authStack"></interceptor-ref>
        <result>/WEB-INF/{2}/{3}.jsp</result>
        <result name="redirect" type="redirect">${url}</result>
    </action>

</package>
</struts>

LoginAction如下:

 package com.van.action;

 import com.opensymphony.xwork2.ActionContext;
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 input(){
    return "success";
}

public String login(){
    //获取session的第一种方法
    if(username.equals("admin")){
        ActionContext.getContext().getSession().put("iaAdmin",true);
    }
    ActionContext.getContext().getSession().put("loginUser",username);
    ActionContext.getContext().put("url","/WEB-INF/user_Article_add");
    return "redirect";
}

public String logout(){
    ActionContext.getContext().getSession().clear();
    ActionContext.getContext().put("url","/WEB-INF/common_Login_input");
    return "redirect";
}

}
地址栏输入信息如下:
http://localhost:8080/sturts/…


点提交后,断点显示直接进入拦截器中,未先进入LoginAction的login方法进行session的配置。

你需要在拦截器里判断是不是在登录啊。

(看完/读完)这篇文章有何感想! SBF胜博发娱乐老虎机的分享…

SBF胜博发娱乐老虎机规范来说,所有可能被throw的exception都要去catch吗?

( SBF胜博发娱乐老虎机 )

有些时候我明明知道这样做绝不会引起exception,还要去catch吗?

又有些时候,被触发的错误是致命的,而且不是因为用户操作而引起的。这样,就算catch了,也是die。这样来说,catch这个exception又有什么意义呢?

然而我总是看到很多说法说一定不要只throw就不管了,不去catch。

那到底应该怎么做呢?

个人觉得错误处理方面,需要把握一个度,而对这个度的把握却又十分困难。

我的理解是:

  • 首先,基本、必要的exception一定要做。

  • 其次是并不需要尽可能的catch所有的exception,否则

    • 错误处理代码冗长

    • 执行效率问题

    • 有些exception catch了,但没有更好的办法处理;比如是代码的bug,反而应该尽可能的把代码的bug暴露出来,然后尽早解决。

  • 最后总结一下,异常处理需要把握一个度,我认为的这个度是:

    • 做基本和必要的异常处理

    • 不刻意为了追求完美而去做所有的异常处理,有些问题应该尽早暴露和解决

我的经验:

  1. Catch已知能够处理的异常,error logging其它异常让程序员手动去处理

  2. 异常处理分层次,在实现自己的模块时,将依赖的第三方模块的异常处理包含在自己的模块内

Java异常处理的10个最佳实践

  • 然而总有人喜欢像折腾轮子一样自己去总结一套,爬坑出来才发现别人造的轮子是那么的不错(笑)。

计算是catch了也不一定就是die了,捕获异常主要是为了处理异常而不是die掉,比如在发送邮件的时候因为网络原因而发送失败的时候,这个时候就抛出异常进行处理将失败的人物放进队列中等待再次处理。
异常是为了程序更健壮

(看完/读完)这篇文章有何感想! SBF胜博发娱乐老虎机的分享…

sbf胜博发娱乐城为什么要写Model?

( sbf胜博发娱乐城 )

Android或者iOS客户端开发为什么要写Model?除了可读性 还有什么?迎合MVC,MVP?

既然提到了可读性,而这一点的重要性是极其重要的,即使没有别的作用,光可读性一条也可以奠定其存在的地位了

为了分层

  • 结构清晰,方便扩展,

  • 代码独立 ,方便复用

(看完/读完)这篇文章有何感想! sbf胜博发娱乐城的分享…

胜博发游戏官网可能是引包重复导致的错误

( 胜博发游戏官网 )

初学spring,在配置之后,一个简单例子返回的时候报错,看样子应该是包重复导致的,但我不清楚是哪两个包导致的错误,下面的报错信息,后面是pox.xml。
希望不要见怪,本人水平确实不高。
报错信息:

严重: Servlet.service() for servlet jsp threw exception
java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/WEB_002dINF/jsp/ajaxJson_jsp, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature
    at org.apache.jsp.WEB_002dINF.jsp.ajaxJson_jsp._jspInit(ajaxJson_jsp.java:31)
    at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1017)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2451)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2440)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
九月 28, 2016 4:50:16 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [springServlet] in context with path [/RXRentSystem] threw exception [java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/WEB_002dINF/jsp/ajaxJson_jsp, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature] with root cause
java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/WEB_002dINF/jsp/ajaxJson_jsp, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature
    at org.apache.jsp.WEB_002dINF.jsp.ajaxJson_jsp._jspInit(ajaxJson_jsp.java:31)
    at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1017)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2451)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2440)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

pox.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>RXRentSystem</groupId>
    <artifactId>RXRentSystem</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>RXRentSystem</name>
    <description />
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <!--common -->

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-spring</artifactId>
            <version>1.2.3</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.3.2.RELEASE</version>
        </dependency>

        <!-- AOP支持 -->
        <dependency>
            <groupId>aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.5.4</version>
        </dependency>

        <dependency>
            <groupId>aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.5.4</version>
        </dependency>

        <!-- Apache Commons -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
            <version>2.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>2.4.2</version>
        </dependency>

        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.2.2.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.2.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>

        

    </dependencies>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <warSourceDirectory>${basedir}/WebRoot</warSourceDirectory>
                    <version>3.1</version>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

(看完/读完)这篇文章有何感想! 胜博发游戏官网的分享…