spring mvc @sessionattributes @ResponseBody 公用报错

[code="java"]

@Controller
@RequestMapping("/user")
@SessionAttributes(LoginConstants.CURRENT_USER)
public class UserContorller {
private UserService userService;
public UserService getUserService() {
return userService;
}

@Autowired
public void setUserService(UserService userService) {
    this.userService = userService;
}

@ResponseBody
@RequestMapping( value="login" ,method=RequestMethod.GET)
public String login(LoginForm loginForm,ModelMap modelMap){
    UserEntity userEntity = new UserEntity();
    userEntity.setName(loginForm.getName());
    userEntity.setPassword(loginForm.getPassword());
    userEntity = userService.login(userEntity);
    if(null != userEntity){//登录成功
        modelMap.addAttribute(LoginConstants.CURRENT_USER, userEntity);
        return "ok";
    }else{//登录失败 
        return "error";
    }
}

}
[/code]

报错如下错误:
[code="java"]
严重: Servlet.service() for servlet springmvc threw exception
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2400)
at org.apache.catalina.connector.Request.getSession(Request.java:2120)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
[/code]

2个回答

@ResponseBody

@RequestMapping( value="login" ,method=RequestMethod.GET)

public String login(LoginForm loginForm,ModelMap modelMap){

UserEntity userEntity = new UserEntity();

userEntity.setName(loginForm.getName());

userEntity.setPassword(loginForm.getPassword());

userEntity = userService.login(userEntity);

if(null != userEntity){//登录成功

modelMap.addAttribute(LoginConstants.CURRENT_USER, userEntity);

return "ok";

}else{//登录失败

return "error";

}

}
请将方法的参数加上该为public String login(HttpSession session, LoginForm loginForm,ModelMap modelMap)

z276356445t
z276356445t 当然有区别, 这是2个不同的域, modelMap相当于一个值栈, 这是spring mvc的一个特性, 而session是servlet自身的, 当然不能这样去比较.
6 年多之前 回复
xsgkaka
xsgkaka 此处添加上HttpSession session的引用是不是意味着将session初始化,也就是创建了session,我在session里面添加 session.setattribute和modelMap.addAttribute这两者在spring里面有没有区别。
6 年多之前 回复

你没有看到吗 在response的时候没有办法创建Session
if(null != userEntity){//登录成功

[color=red][b]在此处创建Session试试[/b][/color]
modelMap.addAttribute(LoginConstants.CURRENT_USER, userEntity);

return "ok";

}else{//登录失败

return "error";

}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Spring MVC ResponseBody
深入浅出Spring MVC原理与技术实战
求教关于Spring MVC @ResponseBody 问题
头一回使用Spring MVC的@ResponseBody注解,但是无法在前端得到响应。rn不知是何原因。代码及配置如下:rn前端VIEW: login.jsprn<%--rn Created by IntelliJ IDEA.rn User: BPMrn Date: 2013/8/3rn Time: 下午 2:10rn To change this template use File | Settings | File Templates.rn--%>rn<%@ page contentType="text/html;charset=utf-8" language="java" pageEncoding="utf-8" %>rnrnrnrn rn rn rn Login Pagernrnrn rn Name: rn Password: rn rnrnrnrnrn后端控制器代码:rnpackage springmvc.controller;rnrnimport org.springframework.stereotype.Controller;rnimport org.springframework.ui.Model;rnimport org.springframework.web.bind.annotation.RequestMapping;rnimport org.springframework.web.bind.annotation.RequestMethod;rnimport org.springframework.web.bind.annotation.RequestParam;rnimport org.springframework.web.bind.annotation.ResponseBody;rnimport org.springframework.web.servlet.ModelAndView;rnrnimport javax.servlet.http.HttpServletResponse;rnimport java.io.PrintWriter;rnrn/**rn * Created with IntelliJ IDEA.rn * User: BPMrn * Date: 2013/6/27rn * Time: 下午 8:16rn * To change this template use File | Settings | File Templates.rn */rnrn@Controllerrnpublic class WebAppController rnrn @RequestMapping(value = "/default.xhtml", method = RequestMethod.GET)rn public ModelAndView redirectIndex() rn ModelAndView mv;rn mv = new ModelAndView("login");rn return mv;rn rnrn @RequestMapping(value = "/validateLogin.xhtml", method = RequestMethod.POST)rn @ResponseBodyrn public String validateLogin(@RequestParam String name, @RequestParam String password) rn String result = "";rn if (name.equals("User") && password.equals("12345")) rn result = "success";rn else rn result = "failure";rn rn return result;rn rnrnrnweb.xml配置:rnrnrn rn encodingFilterrn org.springframework.web.filter.CharacterEncodingFilterrn rn encodingrn UTF-8rn rn rn forceEncodingrn truern rn rn rn encodingFilterrn /*rn rnrn rn Dispatcherrn org.springframework.web.servlet.DispatcherServletrn 1rn rn rn Dispatcherrn *.xhtmlrn rnrn rn rn default.xhtmlrn rnrnrnDispatcher-servlet.xml配置:rnrnrnrn rn rn rnrn rnrn rn rn rn rnrn rnrn rn
Spring MVC @ResponseBody生成的页面在IE8的问题
使用Spring MVC不通过View直接生成一个页面有两种方法: [code=&quot;java&quot;] @RequestMapping(value = &quot;/something&quot;) public void helloWorld(HttpServletResponse response) { response.getWriter().println(&quot;Hello World&quot;) } [/co...
spring mvc @ResponseBody返回中文乱码解决
sping mvc中添加@ResponseBody,返回中文字符串时出现乱码,且在applicationContext-web.xml中已经配置StringHttpMessageConverter text/plain;charset=UTF-8 text/html;charset=UTF-8
spring mvc @ResponseBody返回中文乱码问题
在SpringMVC 的Controller中使用@ResponseBody注解向客户端返回数据时,如果没有特殊设置则中文将显示为乱码,此时需要在Spring-mvc.xml配置文件中加入如下代码: 基于spring3.2以后的配置文件。编码配置需要放在mvc:annotation-driven/之前,否则无效。 &amp;amp;lt;!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射,解...
Spring MVC 中的 @ResponseBody 注解的使用场合
我们已经知道,在 SpringMVC 中使用 @RequestMapping 可以作出HTTP的请求映射,并且在这个注解所作用的方法中,这个请求会被 forward 到该方法所返回的值所对应的路径中。但是,如果我们在方法加上了 @ResponseBody 注解,那么返回值就直接会被作为HTTP响应的内容的响应体部分直接发送给客户端,这样就可以让我们直接把自己想要返回的内容返回到客户端。
Spring MVC @ResponseBody返回中文字符串乱码问题
引起乱码原因为spring mvc使用的默认处理字符串编码为ISO-8859-1,具体参考org.springframework.http.converter.StringHttpMessageConverter类中 public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1"); 第一种解决方法:添加
Spring MVC – Easy REST-Based JSON Services with @ResponseBody
NULL 博文链接:https://nethub2.iteye.com/blog/2329387
spring mvc 注解@ResponseBody返回中文乱码问题解决。
spring-mvc.xml中有个默认的配置是:   改为:           text/plain;charset=UTF-8  text/html;charset=UTF-8          第二种方法是:但仅限于一个方法 @RequestMapping(value="/login",method=RequestMethod
解决Spring MVC @ResponseBody出现问号乱码问题
这两天做项目又出现乱码的问题,后台打印的结果是正常的,但是前台却出现问号乱码,经过在网上查找资料很快就解决了。原因是SpringMVC的@ResponseBody使用的默认处理字符串编码为ISO-8859-1,而我们前台或者客户端的编码一般是UTF-8或者GBK。现将解决方法分享如下! 第一种方法: 对于需要返回字符串的方法添加注解,如下: @RequestMapping(value="
获取Spring MVC注解@ResponseBody的一种实现
一般来说,提供给终端调用的API接口在Controller都会直接使用@ResponseBody来进行注解。此时如果我们想要在其他地方来获取方法的返回值,并做一些操作,此处以保存日志为例。每一个接口返回的都是Result类型,大概如下: @RequestMapping(value="a") @ResponseBody public Result a(){
Spring Mvc中@ResponseBody中文乱码解决汇总
spring 3 mvc 的 @ResponseBody返回数据用起来很方便,但是中文乱码,而且返回的Content-Type不带编码信息,网上有很多解决方法,但是大部分都存在一些问题,这里只介绍一种,如下: 自己写一个继承StringHttpMessageConverter的类UTF8StringHttpMessageConverter,内容参考 StringHttpMessageCo
Spring的@ResponseBody
在看源代码的时候,n @RequestMapping("/delete")n @ResponseBodyn public Map delete(HttpServletRequest request,String fucntionNumber,String ids)n n这里的functionNumber和ids怎么传入到函数体的?n就是spring把什么传入了这个函数?nn新手。对于spring框架不是很了解。
Spring mvc报错与解决方案
JSPs only permit GET POST or HEAD: @RequestMapping(value={"/testTest/{id}"}, method=RequestMethod.PUT) @ResponseBody //添加这一注解 public String putMethod(@PathVariable int id){ return "apa
spring mvc上传报错
[img=https://img-bbs.csdn.net/upload/201407/19/1405736858_958162.png][/img][img=https://img-bbs.csdn.net/upload/201407/19/1405736919_337316.png][/img]rn报[img=https://img-bbs.csdn.net/upload/201407/19/1405736956_373394.png][/img]
Spring MVC Junit单元测试报错
java.lang.ExceptionInInitializerErrorrn at org.springframework.mock.web.MockHttpServletResponse.(MockHttpServletResponse.java:76)rn at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:172)rn at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:100)rn at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:319)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:212)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)rn at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)rn at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:309)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)rnCaused by: java.util.MissingResourceException: Can't find bundle for base name javax.servlet.LocalStrings, locale zh_CNrn at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1499)rn at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)rn at java.util.ResourceBundle.getBundle(ResourceBundle.java:721)rn at javax.servlet.ServletOutputStream.(ServletOutputStream.java:87)rn ... 25 more
spring mvc查询报错
刚接触spring mvc,做了个简单的用户查询,然后用junit运行了下,包一下错误,实在没找到解决办法 ,望各位大神给予下帮助。[code=java]rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'test.Test': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dimeng.modules.treasury.service.ITestService test.Test.testService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dimeng.modules.treasury.service.ITestService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:385)rn at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)rn at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)rn at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:200)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:259)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:261)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:219)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)rn at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)rn at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:363)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)rnCaused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dimeng.modules.treasury.service.ITestService test.Test.testService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dimeng.modules.treasury.service.ITestService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)rn ... 26 morernCaused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dimeng.modules.treasury.service.ITestService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)rn ... 28 morern[/code]
spring mvc一直报错
[code=java]rn[size=13px][color=#FF0000]严重: java.io.FileNotFoundException: jndi:/localhost/spring%20mvc/WEB-INF/classes/net/spring/controller/HelloWorldController.class[/color][/size]rnjava.io.FileNotFoundException: jndi:/localhost/spring%20mvc/WEB-INF/classes/net/spring/controller/HelloWorldController.classrn at org.apache.naming.resources.DirContextURLConnection.getInputStream(DirContextURLConnection.java:389)rn at java.net.URL.openStream(URL.java:1010)rn at com.sun.faces.config.AnnotationScanner.containsAnnotation(AnnotationScanner.java:515)rn at com.sun.faces.config.AnnotationScanner.processWebInfClasses(AnnotationScanner.java:467)rn at com.sun.faces.config.AnnotationScanner.processWebInfClasses(AnnotationScanner.java:437)rn at com.sun.faces.config.AnnotationScanner.processWebInfClasses(AnnotationScanner.java:459)rn at com.sun.faces.config.AnnotationScanner.processWebInfClasses(AnnotationScanner.java:437)rn at com.sun.faces.config.AnnotationScanner.processWebInfClasses(AnnotationScanner.java:459)rn at com.sun.faces.config.AnnotationScanner.processWebInfClasses(AnnotationScanner.java:437)rn at com.sun.faces.config.AnnotationScanner.processWebInfClasses(AnnotationScanner.java:459)rn at com.sun.faces.config.AnnotationScanner.processWebInfClasses(AnnotationScanner.java:437)rn at com.sun.faces.config.AnnotationScanner.processWebInfClasses(AnnotationScanner.java:416)rn at com.sun.faces.config.AnnotationScanner.getAnnotatedClasses(AnnotationScanner.java:214)rn at com.sun.faces.config.ConfigManager$AnnotationScanTask.call(ConfigManager.java:765)rn at com.sun.faces.config.ConfigManager$AnnotationScanTask.call(ConfigManager.java:736)rn at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)rn at java.util.concurrent.FutureTask.run(FutureTask.java:138)rn at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:329)rn at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:223)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)rn at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)rn at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3920)rn at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1271)rn at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1440)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:301)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)rn at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)rn at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)rn at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)rn at java.lang.Thread.run(Thread.java:662)[/code]rnrn总感觉 严重: java.io.FileNotFoundException: jndi:/localhost/spring%20mvc/WEB-INF/classes/net/spring/controller/HelloWorldController.class 这一句话有问题,请教各位有没有遇到过这种问题。。。。。。
spring mvc 注入报错
错误信息如下:rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.service.UploadService com.controller.UploadController.uploadService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.UploadDao com.service.UploadService.uploadDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.dao.UploadDao.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)rn at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)rn at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)rn at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)rn at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)rn at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)rn at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)rn at javax.servlet.GenericServlet.init(GenericServlet.java:158)rn at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)rn at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)rn at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)rn at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)rn at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.service.UploadService com.controller.UploadController.uploadService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.UploadDao com.service.UploadService.uploadDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.dao.UploadDao.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)rn ... 36 morernCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.UploadDao com.service.UploadService.uploadDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uploadDao': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.dao.UploadDao.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1145)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1069)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:967)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)rn ... 38 morern....
spring mvc 请求报错
No mapping found for HTTP request with URI [/Springmvc/test] in DispatcherServlet with dispatche 原因:表单有日期,实体对应字段也是日期类型,所以报错,把实体和库字段设置程String,就会成功保存。 ERROR [org.springframework.web.context.Context...
spring mvc公用controller直接访问不同页面
spring mvc 是传统的以controller为中心的mvc,外部只能通过controller访问,有些情况下两个页面获取的数据相同,只是显示不同,比如区别只是显示同一对象的不同字段,这时也必须提供2个controller,两个controller的区别只是转到不同的页面,并且页面需要的数据已经通过标签方式获取,这样controller中只剩下跳转语句了。 spring mvc提供了一种...
16. Spring MVC视频_处理模型数据之 SessionAttributes 注解
全网第一套基于Spring4.x、涵盖所有企业开发技术点、源码级讲授的 Spring MVC视频。本套视频涵盖 Spring MVC 开发过程中所有的技术问题,多个技术点更是从源代码级别进行分析,授之以渔。学习本套视频后,你会真正理解 Spring MVC 的优雅和简洁,并使你具备开发 Spring MVC 企业级项目的能力。
23. Spring MVC视频_SessionAttributes注解引发的异常
全网第一套基于Spring4.x、涵盖所有企业开发技术点、源码级讲授的 Spring MVC视频。本套视频涵盖 Spring MVC 开发过程中所有的技术问题,多个技术点更是从源代码级别进行分析,授之以渔。学习本套视频后,你会真正理解 Spring MVC 的优雅和简洁,并使你具备开发 Spring MVC 企业级项目的能力。
捕捉 @ResponseBody 报错详细信息
  使用@ResponseBody 报错 很大概率是参数名或类型与后台接受类不匹配,但是报错却没有详细的提示信息, @ResponseBody在controller中加入下面的方法可以捕捉到具体的报错信息     @ResponseStatus(HttpStatus.BAD_REQUEST)     @ExceptionHandler(HttpMessageNotReadableExcep...
spring @ResponseBody 乱码问题解决方案
浏览器请求或者restful工具请求乱码,但是ajax请求可能不乱码哦,可以用下面的js测试一下:&amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;meta charset=&quot;utf-8&quot;&amp;gt; &amp;lt;title&amp;gt;测试乱码&amp;lt;/title&amp;gt; &amp;lt;script type=&quot;text/javascript&quot; src=&quot;
spring的@ResponseBody少了is前缀?
比如有个属性是isOK.rn结果返回的json中is没了,就剩ok了。rn这个怎么处理?
Freemarker 结合 Spring mvc 报错
[b]应该是配置文件的问题,看看这样配置对不对?[/b]rnrn[code=text]rnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrn[/code]
Spring MVC之不报错的404错误
额,其实就是学习MVC期间发生了一个小插曲,我是完全按照设计规范来做的,而且配置文件也检查了好几遍程序就是一个hello程序很干净简洁……但是,就是运行之后显示404错误,在controller里打印的代码看不见说明根本就没进入controller,如果您也出现这样的问题别看控制台了,因为控制台并不能提供什么有效的信息,您可以看那一下problem那个模块,里面是不是报了跟jre或者jdk有关的错
Spring mvc 文件上传接口报错
Could not instantiate bean class [org.springframework.web.multipart.commons.CommonsMultipartFile]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframewor
跪求帮助 Spring mvc 报错
在使用spring2.5时,采用spring2.5的注解MVC 出现错误rn配置文件rnrnrn rn rn rnrn报错信息:rnorg.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/mvc]rnOffending resource: ServletContext resource [/WEB-INF/dispatcherContext.xml]rnrn解决了半天了,就不知道怎么回事,请帮忙,谢谢了
spring mvc报错,如何解决?
严重: Servlet.service() for servlet dispatcher threw exceptionrnrnorg.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException: No matching handler method found for servlet request: path '/login.xhtml', method 'GET', parameters map['op' -> array['valiCodeRedir']]
spring mvc环境部署报错
如下图,我部署spring mvc时报java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServet,当点击链接时就报404,请问这怎么解决?n![图片说明](https://img-ask.csdn.net/upload/201706/15/1497459159_140598.png)n![图片说明](https://img-ask.csdn.net/upload/201706/15/1497459332_743129.png)
cfx Spring 和 Spring MVC一起用报错
问题描述:rn 在做WebService的时候,用CFX技术和Spring进行整合,然后通过WebService的方法调用业务逻辑代码,[u][b]发现用Spring的依赖注入没有成功(失效)[/b][/u]。去调web.xml中有关WebService代码,程序运行成功。rnrnweb.xml文件如下rnrn[code=java]rnrnrn rn contextConfigLocationrn /WEB-INF/beanRefServer.xmlrn rn rn CXFServletrn rn org.apache.cxf.transport.servlet.CXFServletrn rn 0rn rn rn CXFServletrn /services/*rn rn rn rn rn org.springframework.web.context.ContextLoaderListenerrn rn rn rn Set Character Encodingrn rn org.springframework.web.filter.CharacterEncodingFilterrn rn rn encodingrn UTF-8rn rn rn forceEncodingrn truern rn rn rn Set Character Encodingrn /*rn rn rn rn spring3rn rn org.springframework.web.servlet.DispatcherServletrn rn 1rn rnrn rn spring3 rn /rn rn rn index.jsprn rnrn[/code]rnrnController代码rn[code=java]rn@Controllerrn@RequestMapping("/user")rnpublic class UserController rn rn private IUserService userServer;rn private IDeptService deptServer;rn rn public IDeptService getDeptService() rn return deptServer;rn rnrn public void setDeptService(IDeptService deptServer) rn this.deptServer = deptServer;rn rnrn public IUserService getUserService() rn return userServer;rn rnrn public void setUserService(IUserService userServer) rn this.userServer = userServer;rn rnrn @RequestMapping(value="/login",method=RequestMethod.POST)rn public String login(@RequestParam String name,@RequestParam String password,Model model,HttpServletRequest request) throws Exceptionrn TUser user1 = userServer.getUserByName(name);rn if(user1 == null) rn model.addAttribute("message", "用户不存在");rn return "login";rn else if(password == null || !password.equals(user1.getPassword()) )rn model.addAttribute("message", "密码错误");rn return "login";rn else rn request.getSession().setAttribute(Constants.USER_INFO_SESSION, user1);rn return "welcome";rn rn rn以下略...rn[/code]rnrn上面代码中 login()方法时,userServer为null,注入没有成功,请问为何rnrn
解决Spring MVC @ResponseBody返回中文字符串乱码问题
一、现象:使用pojo对象产生的json不会乱码,但使用map存放数据后,再使用json转换工具时就会产生乱码。 * 二、原因:* 网上解决引起乱码原因为spring mvc使用的默认处理字符串编码为ISO-8859-1,具体参考org.springframework.http.converter.StringHttpMessageConverter类中public static final Cha
spring mvc 3.1 使用@ResponseBody注解是不能返回json数据
使用spring 3.1 @ResponseBody注解时出现如下错误rnThe resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headersrnrn最终解决办法是引入rnjackson-core-as和jackson-mapper-asl两个jar包
Spring MVC @ResponseBody注解返回响应流时中文乱码问题的解决
在Spring MVC 的Controller中使用@ResponseBody注解向客户端返回数据时,如果没有特殊设置则中文将显示为乱码,此时需要在Spring-MVC.xml配置文件中加入如下代码: Xml代码   &amp;lt;!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射,解决@ResponseBody乱码问题, 需要在annotation-dri...
spring mvc通过@ResponseBody返回时,ajax接收显示问号(?)
@requestMapping中添加 produces = "text/html;charset=UTF-8" @RequestMapping(value = "/queryDetail",produces = "text/html;charset=UTF-8") public String getName(HttpServerletReuest request){ }
解决Spring MVC @ResponseBody return中文字符串乱码问题
引起乱码原因为springmvc使用的默认处理字符串编码为ISO-8859-1, org.springframework.http.converter.StringHttpMessageConverter类中public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1"); 直接在配置文件中加入
spring mvc 返回通过配置ResponseBody返回json格式的数据
学习了spring mvc后,发现spring mvc返回json数据比struts2要方便,使用@ResponseBody就可以了 @ResponseBody 作用:       该注解用于将Controller的方法返回的对象,通过适当的HttpMessageConverter转换为指定格式后,写入到Response对象的body数据区。 使用时机:       返
spring MVC 中 @ResponseBody 与 Modle 可以同时使用吗?
如题,下面是我的一个Controller层的方法,里面用到了@ResponseBody 与Modle,出现的问题是,通过map返回的数据被正常的转成了json格式传递给页面,但是model里设置的值在jsp页面通过el表达式$lresquestScope.levels却取不到值,自己也网上查了一下,感觉最大的可能性就是由于最后执行@ResponseBody,把model里的值也给转成json格式了,但是我通过浏览器的debug模式没有发现和我往modle里传递的值的相关信息。 我如何做到既能正常的使用@responseBody 的同时又能使用modle呢?rn下面是码码:rn[code=java]@RequestMapping(value="review-find/id",method=RequestMethod.GET)rn @ResponseBodyrn public Map findInfoById(@PathVariable("id")String id,Model model) rn rn this.map = new HashMap();rn TcClasses classes = this.getBaseAllService().getClassReviewManagerService().getInfoById(id);rn map.put("data", classes);rn //得到任课教师信息rn List teachers = this.getBaseAllService().getStartClassCheckManagerService().budgetGetTeacherByClassesId(id);rn map.put("teachers",teachers);rn //得到班级结算基本信息rn TcBasicBalanceSheet balanceSheet = this.getBaseAllService().getClassReviewManagerService().getBasicBalanceSheet(id);rn map.put("balanceSheet",balanceSheet);rn //费用测算等级rn List levels = this.getBaseAllService().getStartClassCheckManagerService().getGradeByCourseId(classes.getSubjectId());rn model.addAttribute("levels", levels);rn rn return map;rn [/code]rn下面是这个方法返给浏览器的信息rn[img=https://img-bbs.csdn.net/upload/201606/29/1467203518_952130.png][/img]
相关热词 c# 去空格去转义符 c#用户登录窗体代码 c# 流 c# linux 可视化 c# mvc 返回图片 c# 像素空间 c# 日期 最后一天 c#字典序排序 c# 截屏取色 c#中的哪些属于托管机制