我正在研究一个java spring mvc应用程序.我用这种方式在我的一个控制器方法中设置了一个cookie:
@RequestMapping(value = {"/news"}, method = RequestMethod.GET)
public ModelAndView news(Locale locale, Model model, HttpServletResponse response, HttpServletRequest request) throws Exception {
...
response.setHeader("Set-Cookie", "test=value; Path=/");
...
modelAndView.setViewName("path/to/my/view");
return modelAndView;
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,我可以test
在浏览器控制台中看到名称和值为"value" 的cookie .现在我想在其他方法中按名称获取cookie值.我怎样才能获得test
cookie的价值?
我正在使用netbeans IDE 8.0.当我在编辑器中右键单击时,一个选项是修复导入(CTRL + SHIFT + I).此选项添加有用的导入并删除未使用的导入.但是如何在整个项目中使用Fix Imports(而不是单个文件)?这样做有什么办法吗?
我已经使用了行,现在使用表单组 CSS.我对这些2感到困惑,如果我想构建表单控件,我应该更喜欢哪一个.似乎都做同样的工作.
我在我的spring mvc项目中使用hibernate,我想连接到oracle 12c数据库.我用了org.hibernate.dialect.Oracle12cDialect
,但是,这回报了我org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.Oracle12cDialect] as strategy [org.hibernate.dialect.Dialect]
.如何为oracle 12c设置方言?我正在使用hibernate 4.3.9
.
我需要expired-url
在我的Spring MVC应用程序中进行配置.这是我的努力,但没有效果:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.addFilterBefore(adminAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(customerAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
.csrf()
.disable()
.authorizeRequests()
.antMatchers("...", "...", "...").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/admin/login")
.and()
.logout()
.addLogoutHandler(customLogoutHandler())
.logoutSuccessHandler(customLogoutSuccessHandler())
.logoutUrl("/logout")
.deleteCookies("remove")
.invalidateHttpSession(true)
.permitAll()
.and()
.sessionManagement()
.maximumSessions(1)
.expiredUrl("/expired");
}
Run Code Online (Sandbox Code Playgroud)
这没有任何效果,当用户的会话超时时,spring不会将他重定向到/expired
url并只是将他重定向到/admin/login
url.
更新:
我在评论和答案中尝试了建议的解决方案,但没有看到任何影响.我也删除了addLogoutHandler()
,logoutSuccessHandler()
两个addFilterBefore()
在方法开始时,但没有工作.
我也用这种方式尝试了另一种解决方案:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.addFilterBefore(sessionManagementFilter(), SessionManagementFilter.class)
.csrf()
.disable()
.authorizeRequests()
.antMatchers("...", "...", "...").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/admin/login")
.and()
.logout()
.logoutUrl("/logout")
.deleteCookies("remove")
.invalidateHttpSession(true) …
Run Code Online (Sandbox Code Playgroud) 我在我的java应用程序中处理Telegram api.我需要使用我的电报帐户进行身份验证和授权,并获取我的特定组的消息列表.为了这个目的,首先我得到了api_id
,api_hash
并且MTProto servers
从电报的网站.其次,我尝试以auth.sendCode
这种方式使用方法授权我的帐户:
...
String url = "https://149.154.167.40:443/auth.sendCode";
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
httpPost.addHeader("charset", "UTF-8");
List<NameValuePair> nameValuePairs = new ArrayList<>();
nameValuePairs.add(new BasicNameValuePair("phone_number", myPhoneNumber));
nameValuePairs.add(new BasicNameValuePair("sms_type", "5"));
nameValuePairs.add(new BasicNameValuePair("api_id", api_id));
nameValuePairs.add(new BasicNameValuePair("api_hash", api_hash));
nameValuePairs.add(new BasicNameValuePair("lang_code", "en"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
HttpResponse response = httpClient.execute(httpPost);
...
Run Code Online (Sandbox Code Playgroud)
但这会让我感到javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
异常.我测试了url http
而不是https
和这返回了404 Not Found
html内容.在java中调用telegram api方法的正确方法是什么?
更新:
我尝试使用 …
我正在开发一个Spring MVC应用程序,我需要访问客户端浏览器名称和版本.
我HttpServletRequest
在我的操作中有一个实例作为参数和使用request.getHeader("User-Agent")
方法,但这Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
在Internet Explorer 9中返回.
我需要确切的数字和版本.这样做有什么工具吗?
我正在研究java spring mvc应用程序,并且有一个关于将视图模型对象映射到数据库模型对象的重要问题.我们的应用程序使用dozer映射器来实现此目的.
假设我有一个Person模型和BaseInformation模型.该BaseInformation模式是可以在所有其他机型上使用,例如一般数据性别,颜色,单位,....
BaseInformation:
class BaseInformation{
private Long id;
private String category;
private String title;
}
Run Code Online (Sandbox Code Playgroud)
这可以有一个像这样的数据库表:
Id | Category | Title
-------------------------
1 | "gender" | "male"
2 | "gender" | "female"
3 | "color" | "red"
4 | "color" | "green"
...
Run Code Online (Sandbox Code Playgroud)
这是我的人物模型的一部分:
public class Person{
...
private BaseInformation gender;
...
}
Run Code Online (Sandbox Code Playgroud)
这是我的RegisterPersonViewModel的一部分
public class RegisterPersonViewModel{
...
private Integer gender_id; …
Run Code Online (Sandbox Code Playgroud) 我在视图中有一个HTML表单,我需要用来自服务器的json变量填写一些输入字段.我不想为每个输入字段编写javascript代码,相反,我想在value
输入标记的属性中访问json变量.
我测试onload
了input
标签的事件,但没有任何影响.
<input type="text" class="form-control" onload="this.value = 'value';" name="company[name]" />
Run Code Online (Sandbox Code Playgroud) 我有一个字符串,如"test.test.test"...".test",我需要访问此字符串中的最后一个"test"字样.请注意,字符串中的"test"数量不受限制.如果java有像php explode
函数这样的方法,一切都是正确的,但....... 我认为从字符串的末尾分割,可以解决我的问题.有没有办法为split
方法指定方向?我知道这个问题的一个解决方案可能是这样的:
String parts[] = fileName.split(".");
//for all parts, while a parts contain "." character, split a part...
Run Code Online (Sandbox Code Playgroud)
但我觉得这个糟糕的解决方案.