spring-mvc

Get jsp output in spring controller as String

时间秒杀一切 提交于 2020-01-03 21:08:14
问题 Isn't there any easy way in Spring 4 by which we can achieve same as following code request.getRequestDispatcher("/WEB-INF/jsp/account_summary.jsp").include(request, response); To get output of a JSP file as a String in our controller. Presently I am using following code for this purpose HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response) { private final StringWriter sw = new StringWriter(); @Override public PrintWriter getWriter() throws IOException { return

EntityMode.Map with Hibernate 4.2.6+ Spring 3.2

眉间皱痕 提交于 2020-01-03 20:06:59
问题 I am trying to use dynamic hibernate model, below is the code snippet to get the session.I have declared " hibernate.default_entity_mode " as " dynamic_map " in hibernate session factory config xml. // Declared at class level @Autowired private SessionFactory sessionFactory; //In specific java-method Session pojoSession = sessionFactory.getCurrentSession(); Session ds = pojoSession.getSession(EntityMode.MAP); Still, I get an exception in eclipse saying-" The method getSession(EntityMode) is

EntityMode.Map with Hibernate 4.2.6+ Spring 3.2

[亡魂溺海] 提交于 2020-01-03 20:06:42
问题 I am trying to use dynamic hibernate model, below is the code snippet to get the session.I have declared " hibernate.default_entity_mode " as " dynamic_map " in hibernate session factory config xml. // Declared at class level @Autowired private SessionFactory sessionFactory; //In specific java-method Session pojoSession = sessionFactory.getCurrentSession(); Session ds = pojoSession.getSession(EntityMode.MAP); Still, I get an exception in eclipse saying-" The method getSession(EntityMode) is

Spring ClassPathXmlApplicationContext NullPointerException

我是研究僧i 提交于 2020-01-03 18:57:36
问题 Trying to use spring. The xml file is under src. I've searched and cannot find the problem. Seems it cant find the xml file. I get the following error: Exception in thread "main" java.lang.ExceptionInInitializerError at org.springframework.core.env.AbstractEnvironment.suppressGetenvAccess(AbstractEnvironment.java:406) at org.springframework.core.env.AbstractEnvironment.getSystemEnvironment(AbstractEnvironment.java:368) at org.springframework.core.env.StandardEnvironment

Java Throwing exceptions vs returning response in catch

吃可爱长大的小学妹 提交于 2020-01-03 18:45:48
问题 I know a lot has been discussed around exception handling, however I need some advice specific to my situation. I am currently working on a Spring MVC application with Controller->Services->DAO layers. The service classes catch mainly two kinds of exceptions HibernateException and IOException . HibernateException because service needs to perform rollback if a transaction did not succeed and IOException since it is an unchecked exception and needs to be caught or thrown and I prefer the first

Can I have the same mapping value with different param in a different Spring controller?

旧城冷巷雨未停 提交于 2020-01-03 17:50:55
问题 Is there any way to accomplish something like this: I have a form used for navigation : <form action="mapping.do"> <input type="submit" value="menuOption01" /> <input type="submit" value="menuOption02" /> </form> The PageController class is too big and has too many dependancies, I need to add another menu option but don't want to add to the complexity. I'd like to have a method in another controller which handles the new menu option. Trying this gives me a Spring configutation error (There is

Dynamically generate a list of available languages in Spring MVC

二次信任 提交于 2020-01-03 17:32:24
问题 I have set up i18n in Spring MVC 3, and it is working correctly. There are several files, each with its own language: messages_en.properties, messages_de.properties, etc. In one of my JSPs, I need to show the users a combo with all available languages, and I would like this list to be dynamic i.e. generated on the fly from the existing language files in the server. Is there any built-in method to generate this list? Or do I have to resort to check the folder where the language files reside

Return @Async method result in Spring MVC and return it to Ajax client - continuation

别等时光非礼了梦想. 提交于 2020-01-03 17:28:39
问题 This is continuation of this question: Return @Async method result in Spring MVC and return it to Ajax client I have @Async task which calculates something and return it to the Future the calculation happens on the request and might take up to 15 minutes. I don't want to create new Ajax request every few seconds to check whether calculation is done and I don't want to keep my connection Open for up to 15 minutes till result is calculated. What might be the best solution for Spring MVC in such

Trying to match an AspectJ pointcut signature for any methods containing a variable

南楼画角 提交于 2020-01-03 17:12:26
问题 I want to create a pointcut that matches any method in my Web controller that contains a ModelMap: pointcut addMenu(ModelMap modelMap) : execution (public String example.web.MyController.*(..)) && args (modelMap); before(ModelMap modelMap) : addMenu(modelMap) { // Do stuff with modelMap... } My problem is that this only matches methods with ONLY the ModelMap parameter, others are not matched because they contain too many parameters. For example, this is not intercepted, due to the "req"

@Async does not work with task:executor

我们两清 提交于 2020-01-03 14:17:04
问题 I'm trying to call a method in Spring-powered bean asynchronously using @Async . I defined an executor in XML: <task:executor id="emailTasksExecutor" pool-size="1" /> and here is my method: @Override @Async("emailTasksExecutor") public void sendEmail() { ... } And the method does not get called at all when I use qualifier ( emailTasksExecutor ). However, if I remove it, everything works ok. But in this case the default executor is used and I need to change this behaviour. I thought the