본문 바로가기
공부/java & Spring

[왕왕왕초보 Spring 실습] javax.el.ELException: Failed to parse the expression

by 고기 2022. 9. 18.

토이 프로젝트를 만들어보고 있는데...

원인도 알았고 해결도 했지만 근본적인 해결방법은 검색해봐도 알 수 없는 에러가 있어 글로 남겨둔다.

내가 설정을 잘못했나 싶기도 한데... 이것도 현재 시점에선 알 수가 없네

 

일단 발생한 에러는 다음과 같고...

결론부터 말하면 내 경우는 변수명을 영어 외 다른 문자를 사용해서 발생한 에러였다.

SEVERE: 서블릿 [jsp]을(를) 위한 Servlet.service() 호출이 예외를 발생시켰습니다.
org.apache.el.parser.ParseException: Encountered " <ILLEGAL_CHARACTER> "\ud14c "" at line 1, column 3.
Was expecting one of:
    "{" ...
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <STRING_LITERAL> ...
    "true" ...
    "false" ...
    "null" ...
    "(" ...
    "[" ...
    "!" ...
    "not" ...
    "empty" ...
    "-" ...
    <IDENTIFIER> ...
    <IDENTIFIER> ...
    "(" ...
    
	at org.apache.el.parser.ELParser.generateParseException(ELParser.java:3897)
	at org.apache.el.parser.ELParser.jj_consume_token(ELParser.java:3747)
	at org.apache.el.parser.ELParser.Assignment(ELParser.java:315)
	at org.apache.el.parser.ELParser.Semicolon(ELParser.java:203)
	at org.apache.el.parser.ELParser.Expression(ELParser.java:196)
	at org.apache.el.parser.ELParser.DynamicExpression(ELParser.java:162)
	at org.apache.el.parser.ELParser.CompositeExpression(ELParser.java:46)
	at org.apache.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:118)
	at org.apache.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:179)
	at org.apache.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:243)
	at org.apache.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:60)
	at org.apache.jasper.compiler.Validator$ValidateVisitor.prepareExpression(Validator.java:1642)
	at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:771)
	at org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:959)
	at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2385)
	at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2437)
	at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2443)
	at org.apache.jasper.compiler.Node$Root.accept(Node.java:471)
	at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2385)
	at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1869)
	at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:220)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:350)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
	at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:597)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:383)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:331)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:462)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:388)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	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:197)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:367)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:639)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:882)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1647)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.base/java.lang.Thread.run(Thread.java:834)

 

이 에러에 대해 구글 선생님에게 여쭤보면

 

case1. 단순 오타

case2. 주석문에 jstl 들어가있는경우

case3. $ 대신 #로 작성한 경우

 

이런 대단한 내용들을 알려주신다.

하지만 선생님께서 알려주신대로 해서 문제가 해결되었으면 글을 쓰지 않았겠지.

 

이건 문제가 되었던 코드의 샘플인데, 값을 model에 담아서 jsp로 보내는 코드다.

@RequestMapping(value="/searchInfo.do", method=RequestMethod.GET)
	public String searchInfo(Model model, HttpServletRequest request) {

		
		String test1 = "테스트입니다~";
		model.addAttribute("테스트", test1);
		
		return "/searchInfo";
	}

 

jsp에서 jstl로 model값을 출력해본다.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
<head>
	<title>Home</title>
</head>
<body>	
	${테스트}	
	
</body>
</html>

 

오잉..

눈을 크게 뜨고 코드를 두리번두리번 해봐도 뭐가 문제인지 잘 모르겠네.

뭐... 문제가 있었으니까 에러가 났겠지...

 

이것저것 시도해봤는데 정확히 맞는지는 모르겠지만 jstl에서 호출하는 변수명에 숫자나 한글이 들어가서 발생하는 문제였던 것 같다...

 

해결한 코드는 다음과 같다.

라기보단 그냥 한글을 영어로 변경해준 것 뿐이지만...

@RequestMapping(value="/searchInfo.do", method=RequestMethod.GET)
	public String searchInfo(Model model, HttpServletRequest request) {

		
		String test1 = "테스트입니다~";
		model.addAttribute("first", test1);
		
		return "/searchInfo";
	}

 

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
<head>
	<title>Home</title>
</head>
<body>	
	${first}	
	
</body>
</html>

 

 

 

 

댓글