我正在尝试用Java获取发布数据.看起来它应该是最简单的事情之一吗?我的意思是,HttpServletRequest.getParameter必须做对吗?那么如何获得原始发布数据呢?
我发现HttpServletRequest获取JSON POST数据并使用Kdeveloper的代码从请求中提取发布数据.它有效,但有一个问题:我只能获得一次这样的帖子数据.
下面是我用Kdeveloper代码制作的方法:
public static String getPostData(HttpServletRequest req) {
StringBuilder sb = new StringBuilder();
try {
BufferedReader reader = req.getReader();
reader.mark(10000);
String line;
do {
line = reader.readLine();
sb.append(line).append("\n");
} while (line != null);
reader.reset();
// do NOT close the reader here, or you won't be able to get the post data twice
} catch(IOException e) {
logger.warn("getPostData couldn't.. get the post data", e); // This has happened if the request's reader is closed
} …Run Code Online (Sandbox Code Playgroud) 我试图用机械化刮一个表网站.我想刮第二排.
当我跑:
agent.page.search('table.ea').search('tr')[-2].search('td').map{ |n| n.text }
我希望它会刮掉整排.但相反它只是刮擦:["2011-02-17","0,00"]
为什么不抓取行中的所有列,而只是第一列和最后一列?
Xpath: / html/body/center/table/tbody/tr [2]/td [2]/table/tbody/tr [3]/td/table/tbody/tr [2]/td/table/tbody/tr [2]
CSS路径: html体中心表tbody tr td table tbody tr td table tbody tr td table.ea tbody tr td.total
该页面与此类似:
<table><table><table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="ea">
<tr>
<th><a href="#">Date</a></th>
<th><a href="#">One</a></th>
<th><a href="#">Two</a></th>
<th><a href="#">Three</a></th>
<th><a href="#">Four</a></th>
<th><a href="#">Five</a></th>
<th><a href="#">Six</a></th>
<th><a href="#">Seven</a></th>
<th><a href="#">Eight</a></th>
</tr>
<tr>
<td><a href="#">2011-02-17</a></td>
<td align="right">0</td>
<td align="right">0</td>
<td align="right">0,00</td>
<td align="right">0</td>
<td align="right">0</td>
<td align="right">0</td>
<td align="right">0</td>
<td align="right">387</td>
<td …Run Code Online (Sandbox Code Playgroud) hpricot ruby-on-rails nokogiri ruby-on-rails-3 mechanize-ruby
guava(或其他java库)在Python中是否有类似reduce()函数的东西?
我正在寻找像这样的东西http://docs.python.org/library/functions.html#reduce
我正在尝试使用javascript sdk恢复我的facebook新闻Feed中的上周帖子.我能够获得第一页,但后来,我不知道如何继续迭代其他页面.我用以下代码尝试过:
$('#loadPosts').bind('click', function() {
FB.api('/me/home',{since:'last week'}, getPosts);
});
getPosts = function(response){
for (element in response.data){
post = response.data[element]
console.log(post);
}
previousPage = response.paging.previous;
console.log(previousPage);
// can i call FB.api(previousPage, getPosts); ??
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个URL作为上一页,我不知道如何从该URL进行javascript FB.api调用.有任何想法吗?
我试图找出在我的django应用程序中实现基于令牌的身份验证的最佳方法.一个外部的非django应用程序正在设置一个带有令牌的cookie,我有一个可以根据该令牌检索用户信息的web服务.如果用户设置了cookie,则他们不需要在我的站点上进行身份验证,并且应该根据Web服务传回的信息自动登录.在我看来,有几个不同的选项来执行实际检查,我不确定哪个是最好的:
login_required.LOGIN_REDIRECT_URL将在ajax调用中检查/验证cookie 的页面,并在cookie经过身份验证时自动重定向回引用者.我有遗失的选择吗?理想情况下,有一种方法可以将其构建login_required,而无需编写自定义装饰器.
我正在使用Paperclip 2.3.8运行Rails 3.0.3.我有两个模型,称它们为"Post"和"Image".Image是一个包含Paperclip图像文件的对象,用于动态地将图像添加到Posts.图片属于Post,Post有很多图片.
邮政模式:
class Post < ActiveRecord::Base
has_many :images
accepts_nested_attributes_for :images, :reject_if => lambda { |a| a[:image].blank? }, :allow_destroy => true
end
Run Code Online (Sandbox Code Playgroud)
图像模型:
class Image < ActiveRecord::Base
belongs_to :post
has_attached_file :image,
:styles => {
:thumb=> "100x100#",
:small => "300x300>" }
end
Run Code Online (Sandbox Code Playgroud)
我有一个表单,我想动态添加和删除图像.如果图像是正在上传的新图像,我想显示file_field; 否则,如果图像已经存在,我想显示图像和删除链接.我跟着Ryan Bates在嵌套表格上的Railscasts.动态添加图像是有效的,但是对_destory的调用没有触发.帖子包含"_destroy"=>"1",但在HTTP Post事件之后,id为7的图像仍然存在.以下是HTTP Post的摘录:
"images_attributes"=>{
"0"=>{"id"=>"7", "_destroy"=>"1"},
"1"=>{"id"=>"8", "_destroy"=>"false"},
"2"=>{"id"=>"9", "_destroy"=>"false"},
"3"=>{"id"=>"10", "_destroy"=>"false"}}
Run Code Online (Sandbox Code Playgroud)
这是表单的样子:
<%= form_for @post, :html => { :multipart => true } do |f| %>
<%= f.label :images, 'Images' %><br />
<div class="field">
<%= f.fields_for …Run Code Online (Sandbox Code Playgroud) ruby-on-rails paperclip nested-forms nested-attributes ruby-on-rails-3
你知道在视图中是否可以应用边框类型?
我可以做这个
#import <QuartzCore/QuartzCore.h>
...
view.layer.borderColor = [UIColor redColor].CGColor;
view.layer.borderWidth = 3.0f;
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在我的视图中应用不同的边框( - - - - - ,---------等).我该怎么做?
谢谢你的时间!
我曾经用mysql开发一切,本周有机会与postgresql一起工作,为什么不呢!
我总是被告知postgresql有更大的功能集.
我读了一些wiki,但大部分信息都已经过时了.
我失踪的最佳功能是什么?像部分索引等.
另外,我会想念mysql的东西?
我想为特定的jQuery对象添加自定义方法:
$('#DOMelement').customFunc(param); // not a reality
Run Code Online (Sandbox Code Playgroud)
目前,我有:
var customFunc = function(param) {
// do something special
}
$('#DOMelement').data('customFunc', customFunc);
Run Code Online (Sandbox Code Playgroud)
然后我称之为:
var cF = $('#DOMelement').data('customFunc');
cF(param);
Run Code Online (Sandbox Code Playgroud)
所有这一切都有效,但这很痛苦.有更好的解决方案吗?除了编写一个广泛的插件?