新手求助getWriter() has already been called

做微信项目的时候遇到的问题,就是注册界面用户在输入用户名后会在用户表和注册表中查找有没有这个用户名,如果有的话,就显示该用户已经注册,没有的话可以注册,我在测试的时候发现如果是表中已经有了的数据就没有问题,如果是表中没有的数据就会报这个错误,但是程序可以正常运行,这个是什么原因导致的呢?

public List<Record> validUsername() {

return Db.find("SELECT sys_user_reg.`user_name` FROM sys_user_reg");

},这个是service里的代码

public void validUsername(){

    System.out.println("****RegisterController validUsername*******");

    List<Record> regNameList = reService.validUsername();

    String username = getPara("user_name");

    String text = null;

    for(Record re : regNameList) {

    if(StrKit.notBlank(username)&&re.getStr("user_name").equals(username)) {

    text = "该用户已存在";

    break;

    }

    }

    //renderJson(o);

    renderText(text);

    },这个是controller里的代码

function testName(){

var user_name = $("#user_name").val();

if(user_name == ""||user_name == null){

mui.alert('用户名不能为空', '', function() {

return;

});

}else{

$.ajax({

url:'validUsername',

data:{"user_name":user_name},

type:'post',

success:function(data){

if(data!=null){

mui.alert( "该用户名已存在", '', function() {

window.location.reload();

});

}

},error:function(){

},这个是前台注册界面的代码,

2019-08-26 13:44:27 ERROR [com.jfinal.core.JFinalFilter.doFilter] - /wx/me/register/validUsername

java.lang.IllegalStateException: getWriter() has already been called for this response

at org.apache.catalina.connector.Response.getOutputStream(Response.java:549)

at org.apache.catalina.connector.ResponseFacade.getOutputStream(ResponseFacade.java:194)

at com.jfinal.render.TemplateRender.render(TemplateRender.java:60)

at com.jfinal.render.ErrorRender.render(ErrorRender.java:51)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:141)

at com.kedao.sys.handler.GlobalHandler.handle(GlobalHandler.java:37)

at com.jfinal.ext.handler.UrlSkipHandler.handle(UrlSkipHandler.java:46)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)

at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)

at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)

at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)

at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)

at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)

at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:748)

这些是报错信息@Jfinal,求波总指点一下谢谢

评论区

JFinal

2019-08-26 15:24

jfinal 的 render 在使用 response.getWriter() 时发现你的项目中的别的代码已经调用并使用过一次了,在项目中找一下 response.getWriter() 这类代码,去掉它即可

龙龙座

2019-08-26 20:08

@JFinal OK问题解决了谢谢波总

热门分享

扫码入社