【java – 如何在JOptionPane.showConfirmDialog中的组件上requestFocus?】教程文章相关的互联网学习教程文章

java – AspectJ – 记录HttpServletRequest【代码】

我想劫持HTTPServletRequest并使用AspectJ从它中记录一些值.但是,JoinPoint中的最终结果是“RequestFacade”对象.我可以用这个对象做很多事情.我的记录策略是错的吗?如何从HttpServletRequest获取有用的信息?如果我必须在调用方法之前解开它,那么这种方法在我的应用程序中就失去了AOP的目的. 我正在使用Glassfish服务器,如果这有所作为.@Before("execution(* Service.testAuditRecord(..))") public void logBefore(JoinPoint jo...

java – 如何在使用okhttp时将Map添加到RequestBody而不是单独添加键值对?【代码】

如果我有这个:RequestBody formBody = new FormEncodingBuilder().add("email", "Jurassic@Park.com").add("tel", "90301171XX").build();但是我没有单独添加键值对,而只是想添加一个具有可变大小的map类型的变量,我该如何添加呢?解决方法:如何自己迭代地图并添加每个键/值?例:private FormEncodingBuilder makeBuilderFromMap(final Map<String, String> map) {FormEncodingBuilder formBody = new FormEncodingBuilder();for...

java – @RequestBody没有使用Rest服务【代码】

我正在使用Spring开发一个使用AngularJS和WildFly的Web应用程序. 我的问题是我疯了,因为注释@requestBody似乎工作错误. 这是我的服务:@ResponseBody @RequestMapping(value = "/keyuser", method = RequestMethod.POST,consumes = "application/json") public KeyProfileUserSummary updateEmployee(@RequestBody KeyProfileUserSummary keyUser) { return null; }这是我的对象KeyProfileUserSummary的成员:private Integer id; ...

java – @RequestMapping注释中路径和变量之间的Spring MVC差异【代码】

我想知道在Controller类中Spring MVC中的Path和Variable之间有什么区别.@RequestMapping("/home") @RequestMapping(value = "/home") @RequestMapping(path = "/home")基于Spring Documentation Spring 5 Annotation Type RequestMapping,路径是value的别名,值是路径的别名.我想知道这3个RequestMapping的定义和区别.解决方法:@RequestMapping(“/ home”)和@RequestMapping(value =“/ home”)之间没有区别.但是如果你想添加一些其...

java – 当它在代理后面时,如何在jspx中可靠地访问HttpServletRequest?【代码】

我有一个需要知道当前HttpServletRequest的getServerName()的jspx. jspx可以从它的bean中使用#{mybean.serverName}获取它,如下所示:public String getServerName() {HttpServletRequest request = (HttpServletRequest) FacesInstance.getCurrentInstance().getExternalContent().getRequest();return request.getServerName(); }但是,当它在代理(带有mod_proxy的Apache)后面提供时,getServerName()有时会返回节点的主机名而不是前...

java – 如何使用Spring RequestMapping区分域【代码】

我正在尝试使用不同的方法,具体取决于请求发送到哪个域. 例如@RequestMapping(value = "/index.html", domain = "google.de", method = RequestMethod.GET) public ModelAndView handleDeRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { }@RequestMapping(value = "/index.html", domain = "google.com", method = RequestMethod.GET) public ModelAndView handleComRequest(HttpServletRe...

java – Spring @RequestParam和req.getParameter(“xx”)的工作方式不同吗?【代码】

请理解我的英语不好. 我使用Spring MVC并替换了这个源代码@RequestMapping("/ajax/add_server") public void addServer(HttpServletRequest request, HttpServletResponse response) throws Exception {String host = request.getParameter("host");String port = request.getParameter("port");String state = request.getParameter("state");serverService.addServer(host, port, state); }至@RequestMapping("/ajax/add_server"...

java – Android WebDriver. XMLHttpRequest无法加载“URL”. Access-Control-Allow-Origin不允许使用Origin“URL”. at【代码】

我正在使用Selenium WebDriver和Java在Nexus 10(Adndroid 4.2)上运行自动化测试.我面临的错误是:XMLHttpRequest cannot load 'URL1'. Origin 'URL2' is not allowed by Access- Control-Allow-Origin. at null:1> URL1 – 基于json的后端;> URL2 – 前端. FireFox,Chrome,IE 10不会出现此错误.但Android上的WebDriver始终会出现此错误.由于它登录系统不可用. WebDriver能够点击,发送凯斯等. 所以问题是:是否存在任何解决方法以...

java – Spring MVC @ModelAttribute方法返回“Bad request”400【代码】

美好的一天.我遇到了一个问题:我正在尝试发送带有一些属性的POST请求,但是我得到了“Bad request”响应. 这是我的控制器:@Controller @RequestMapping("/group") public class GroupController {private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(GroupController.class);@Autowiredprivate GroupService groupService;@RequestMapping(value = "/add", method = RequestMe...

java – Spring:当我的类已经使用RestController注释时,为什么还要使用RequestBody【代码】

我目前正在使用Java和Spring作为我的Web服务应用程序.我正在使用@RestController注释,希望不再需要使用@ResponseBody和@RequestBody注释.遗憾的是,删除@RequestBody注释会导致序列化失败. 这是我的代码,它没有将请求主体映射到我的方法参数:@RestController @RequestMapping(value = "/member", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VAL...

java – Spring在@RequestBody中反序列化一个LocalDate与@RequestParam中的一个不同 – 为什么,它们可以相同吗?【代码】

问题:Spring似乎对LocalDate使用不同的反序列化方法,具体取决于它是出现在@RequestBody还是请求@ReqestParam中 – 这是否正确,如果是这样,有没有办法在整个应用程序中将它们配置为相同? 背景:在我的@RestController中,我有两个方法 – 一个GET和一个POST. GET期望一个类型为LocalDate的请求参数(“date”); POST期望一个JSON对象,其中一个键(“日期”)的类型为LocalDate.他们的签名类似于以下内容:@RequestMapping(value = "/e...

java – Spring Boot中的每个@RequestBody都需要一个单独的对象【代码】

到目前为止,我已经使用Spring Boot完成了一个(REST)项目并且非常喜欢它.我发现有点狡猾的一件事是我对@RequestBody的理解. 假设我有以下POST方法来登录用户.我的用户实体可能包含的属性不仅仅是我希望发布请求的用户名和密码.在这种情况下,我没有看到任何其他选项,只能创建一个额外的对象(LoginRequest)来保存传入数据的数据.@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)public Re...

java – 从ServletRequest获取Cookie【代码】

我正在使用ServletRequestListener附加到新请求,获取ServletRequest对象并从中提取cookie. 我注意到只有HTTPServletRequest有cookie但我没有在这两个对象之间找到连接. 可以使用吗?HttpServletRequest request = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());在RequestInitialized方法中检索请求? (我确实希望在每个请求上运行) 仅供参考 – 这一切都在JSF 1.2应用程序中完成解...

spring的multipartResolver和java后端获取的MultipartHttpServletRequest方法对比

这两天在用spring进行上传上遇到问题,今天进行了问题的排查,这个过程也增加了我看spring源码的兴趣!还是很有收获的! 首先先给A组提供了上传接口,并没有在spring的配置文件进行multipartResolver的配置,后台Controller的java的获取为: /** *Saves temporary files to the servlet containers temporary directory. Needs to be initialized either by an application context or via the constructor that takes a ServletCo...

java – request.getRemoteUser()有时会返回null【代码】

我有一个使用struts2结合旧式servlet的java-web-application.使用Acegi安全性. 在我的servlet中,我正在记录用户正在尝试做什么以及它是哪个用户.使用request.getRemoteUser()来获取用户 但是对于我的大人物,结果并不一致.大多数情况下,getRemoteUser()返回正确的用户名,但每隔一段时间我就会得到一个空值. 这背后的原因是什么? 编辑:在您的反馈之后,我发现servlet-urls根本没有被安全保护.这样可能会导致getRemoteUser()为null.我...