我需要在登录控制器中设置一个带重定向的cookie.我使用下面的代码设置cookie.
@RequestMapping("/fbresponse")
public String getToken(@RequestParam(required = false, value = "code") String code, HttpServletResponse sResponse) {
sResponse.addCookie(new Cookie("logged", "123"));
return "redirect:"+user.getLastPage();
}
Run Code Online (Sandbox Code Playgroud)
在我的索引中,我尝试使用以下代码来检索cookie:
@RequestMapping("/")
public String getIndex(@CookieValue(value="logged", required=false)String test){
user.setLastPage("/");
loginCheck();
System.out.println(test);
return "index";
}
Run Code Online (Sandbox Code Playgroud)
但它总是返回null.我尝试返回新的ModelAndView.它也没有用,因为我需要模型中的一些组件,它不符合我的要求.如何设置和检索cookie?是否可以通过重定向来实现?
更新 我在登录控制器中有类级别@RequestMapping.
@Controller
@RequestMapping("/login")
public class LoginController {
@RequestMapping("/fbresponse")
public String getToken(@RequestParam(required = false, value = "code") String code, HttpServletResponse sResponse) {
sResponse.addCookie(new Cookie("logged", "123"));
return "redirect:"+user.getLastPage();
}
}
Run Code Online (Sandbox Code Playgroud)
当我删除类级别请求映射时添加cookie工作.如何使用类级别请求映射正确添加cookie?
写了一个小脚本一起工作php5-cgi使用fork(),exec()和管道.当输出php5-cgi很小时,下面的脚本运行良好.但是当它相当大时(<?php phpinfo(); ?>在输入文件中使用时),它不会返回任何内容.
#include<netinet/in.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<unistd.h>
#include<fcntl.h>
int main(int argc, char const *argv[]) {
int status;
int link[2];
char out[4096];
char * arg[3]={"php5-cgi","a.php",0};
if (pipe(link)==-1){
perror("pipe");
}
int pid=fork();
if (!pid){
dup2 (link[1], 1);
close(link[0]);
execvp("php5-cgi", arg);
} else {
waitpid(pid, &status,0);
close(link[1]); // parent doesn't write
char reading_buf[1];
while(read(link[0], reading_buf, 1) > 0){
write(1, reading_buf, 1);
}
close(link[0]);
}
printf("%s\n", "end");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我认为这是由于管道溢出造成的.我有办法解决这个问题吗?或者有没有其他方法来处理大量产品?
我需要在R 中创建具有 50 名员工的 ID 和性别的数据框。为此,我将此代码与gl()函数一起使用。
gender<-gl(2, 25, label=c("Male", "Female"))
id<-1:50
df <- data.frame(id, gender)
Run Code Online (Sandbox Code Playgroud)
但这里的问题是前 25 行是“男性”,接下来的 25 行是“女性”。我想随机生成性别,每个性别有 50% 的机会。无论如何在R中做到这一点?