Tag: spring mvc

在mongodb聚合中查找

以下bson是personaddress集合: { “id” : “123456”, “name” : “foo”, “address” : [ { “local” : “yes”, “location” : [ { “place” : { “_id”:”VZG”, }, “place_lat” : “18”, “place_lan” : “83”, }, { “place” : { “name” : “kerala”, “district” : “palakkad”, “pincode” : “5203689”, }, “place_lat” : “18”, “place_lan” : “83”, } ] } ] […]

SpringMVC自定义集合编辑器不向Jsp返回数据

我在spring绑定了一个多选列表,该项目没有从DAO获取数据,而是从另一个选择选项列表中添加数据。 用户单击一个按钮,数据将使用jquery发送到多选选项列表。 当表单发布时,项目不会发生数据绑定,因为它是一个复杂的数据类型,因此我注册了CustomEditor并将其附加到@initbinder。 编辑我更新了代码, CollectionEditor现在返回一个公民列表回到视图但是我无法获取列表中的数据来填充选择选项。 我正在尝试向列表中添加元素,但是当从服务器返回时,jsp仍然选择保持为null。 下面是代码: CustomCollectionEditor @InitBinder(“crime”) protected void initBinder(WebDataBinder binder, HttpServletRequest request, ServletRequestDataBinder victimbinder){ victimbinder.registerCustomEditor(List.class, “victims”, new CustomCollectionEditor(List.class){ protected Object convertElement(Object element){ Citizens victims = new Citizens(); String ssNumber = “”; if (element instanceof String){ ssNumber = (String) element; } logger.debug(“element is ;” +element); try { int socialSecurityNumber = Integer.parseInt(ssNumber); victims = […]

spring注释不起作用

我从Spring Framework开始,想要使用annotatios做一个HelloWorld,我已经让它创建了一个控制器和一个视图,我猜是基本的你好工作; 但是,我想使用annotatios因为我不能再使用SimpleFormController(不推荐使用)。 我得到的错误是Estado HTTP 404 – /av/index.jsp 我正在使用Netbeans,我基于它提供的基本模板的示例。 我有以下文件,我很确定这是一个错误的配置,但我找不到任何可以帮助我到目前为止。 提前致谢。 web.xml中 contextConfigLocation /WEB-INF/applicationContext.xml org.springframework.web.context.ContextLoaderListener dispatcher org.springframework.web.servlet.DispatcherServlet 1 dispatcher *.do 30 redirect.jsp 调度员servlet.xml中 / .jsp indexController.java package controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.portlet.ModelAndView; @Controller public class IndexController { @RequestMapping(value=”/index.do”, method= RequestMethod.GET) public ModelAndView inicio (){ ModelAndView mv = new ModelAndView(“index”); mv.addObject(“usuario”, “jaxkodex”); […]

为什么我收到响应代码:非HTTP响应代码:java.net.SocketException?

我正在尝试使用JMeter将请求发送到我在localhost上运行的应用程序,但由于java.net.SocketException,许多请求都失败了。 我在控制台中没有看到任何exception。 我读了这些问题1和问题2,但没有多大帮助。 我的代码如下: try { return myService.findItems(group); } catch (NullPointerException n) { n.printStackTrace(); } catch (HibernateException h) { h.printStackTrace(); } catch (IOException i) { i.printStackTrace(); } return null; 知识库 public LinkedHashMap findItems(String group) throws NullPointerException, HibernateException, IOException { Session session = sessionFactory.getCurrentSession(); ….. //request is sent to database return items; } 我的JMeter配置的屏幕截图

Spring MVC响应编码问题

在过去几个小时里,我已经阅读了很多关于这个主题的内容,到目前为止还没有任何工作。 我正在尝试返回包含“奇数”某些字符的响应。 这是一个例子,非常简单: @ResponseBody @RequestMapping(value=”test”) public String test(){ String test = “čćžđš”; System.out.println(test); logger.info(test); return test; } 这是我的web.xml ,因为我找到了一些CharacterEncodingFilter帮助的答案(虽然不是我的情况)。 我使用POST方法,因为我读到这适用于POST。 也找到了这个答案 (相关)。 也没有帮助。 当我调试它时会出现正确的值,但是当我打印时它没有,因为它可以在下面看到: 当我从jmeter测试时,响应似乎没问题, Content-Type是text/html;charset=UTF-8 这是一个截图。 http://i56.tinypic.com/14lt653.jpg 我认为正确的方法是返回UTF-8,也许我错了。

为什么BindingResult必须关注@Valid?

当我遇到错误时,我很难让我的Spring MVCvalidation返回页面提交页面。 我终于解决了这个问题,注意到BindingResult需要在我正在validation的表单参数旁边。 例如,如果我将spring.io教程( http://spring.io/guides/gs/validating-form-input/ )中的checkPersonInfo方法修改为 – @RequestMapping(value=”/”, method=RequestMethod.POST) public String checkPersonInfo(@Valid Person person, BindingResult bindingResult, Model model) { if (bindingResult.hasErrors()) { return “form”; } return “redirect:/results”; } 然后它将工作并重定向到表单页面,但如果我将其更改为 – @RequestMapping(value=”/”, method=RequestMethod.POST) public String checkPersonInfo(@Valid Person person, Model model, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return “form”; } return “redirect:/results”; } 然后它重定向到/ errors 这是什么原因?

带有{}大括号的Spring MVC @Path变量

我正在使用弹簧靴开发应用程序。 在REST控制器中,我更喜欢使用路径变量( @PathVariabale注释)。 我的代码获取路径变量,但它在url中包含{}大括号。 请任何人建议我解决这个问题 @RequestMapping(value = “/user/item/{loginName}”, method = RequestMethod.GET) public void getSourceDetails(@PathVariable String loginName) { try { System.out.println(loginName); // it print like this {john} } catch (Exception e) { LOG.error(e); } } url http://localhost:8080/user/item/{john} 输出控制器 {约翰}

如何从资源文件夹中获取文件。 Spring框架

我正在尝试解组我的xml文件: public Object convertFromXMLToObject(String xmlfile) throws IOException { FileInputStream is = null; File file = new File(String.valueOf(this.getClass().getResource(“xmlToParse/companies.xml”))); try { is = new FileInputStream(file); return getUnmarshaller().unmarshal(new StreamSource(is)); } finally { if (is != null) { is.close(); } } } 但我得到这个错误:java.io.FileNotFoundException:null(没有这样的文件或目录) 这是我的结构: 为什么我无法从资源文件夹中获取文件? 谢谢。 更新。 重构后, URL url = this.getClass()。getResource(“/ xmlToParse / companies.xml”); 文件file = new File(url.getPath()); […]

@Autowire奇怪的问题

自动assembly时我有一种奇怪的行为 我有类似这样的代码,它的工作原理 @Controller public class Class1 { @Autowired private Class2 object2; … } @Service @Transactional public class Class2{ … } 问题是我需要Class2实现一个接口所以我只改变了Class2所以它现在就像: @Controller public class Class1 { @Autowired private Class2 object2; … } @Service @Transactional public class Class2 implements IServiceReference{ … } public interface IServiceReference { public T reference(PK id); } 使用此代码,我得到一个org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of […]

如何使用Spring安全性获取会话超时消息

我希望在会话到期时获得会话超时消息.Below是我的spring-security.xml 根据我的知识,当会话到期时使用上面的代码它应该重定向到/?timeout=true OR /Timeout?timeout=true 。 退出时应该转到/ 。 但在我注销的情况下,它也会重定向到invalid-session-url所以我总是在正常注销和会话超时时都获得超时。 请帮我区分一下。 UPDATE /logout请求包含 session = request.getSession(); session.invalidate(); session = null;