안녕하세요.자바 JSP - if() - else()를 사용한 스크립틀릿 사용
I는 다음의 설정을 가지고
-
사용자가 텍스트 필드의 양을 입력 한 후에 버튼 중 하나를 클릭하면 그 후, 브라우저에 HTML 양식 출력
- 가 JSP,
- 데이터 특정 계산을 수행하고 결과 데이터를 다시 JSP로 보내는 서블릿으로 보내집니다.
- 그러면 JSP는 결과 데이터를 표시하고 계속 실행하므로 사용자는 프로그램을 사용하여 더 많은 반복을 할 수 있습니다.
은 내가 JSP를 코딩하는 것을 시도하고 같은 그것이 2 개 세션 속성의 존재, 최초로 확인, "균형" 와 "formattedBal"를 실행하면. 이러한 속성이 존재하지 않으면 (즉, 사용자가 사용자가 URL 주소를 클릭 한 후 JSP를 처음 실행하는 경우) JSP 실행은 이러한 세션 속성을 만들어 할당해야합니다. 이 속성 들인 이 존재한다면 (이것은 JSP의 초기 실행이 아니라 서블릿이 사용자에게 을 JSP로 되 돌렸고 결과 데이터, 즉 null이 아닌 세션 속성을 JSP에 보내면 JSP가 적절한 코딩 위치에 상기 세션 속성의 값을 나타내는 HTML 출력 ( )을 단순히 실행하면된다. - <% 태그
<html>
<hr> <!--Horizontal line.-->
<title>Online Bank ATM Simulator</title> <!--Title to show on browser title bar.-->
<h1 align = "center">Bank ATM Simulation</h1> <!--Page heading, centered on page.-->
<SCRIPT LANGUAGE = JAVASCRIPT>
<!--
function checkAttributes()
{
<%
// Set balance and formatted balance as session attributes.
if(request.getSession().getAttribute("balance") = null && request.getSession().getAttribute("formattedBal") = null)
{
request.getSession().setAttribute("balance", 0);
request.getSession().setAttribute("formattedBal", "$0");
}
%>
}
-->
</SCRIPT>
<body onLoad = "checkAttributes()", "amount.focus()"> <!--Set focus to the text-field.-->
<form method = "POST" action = "../servlet/JSPBank"> <!--Form method and submission address.-->
<center> <!--Tag to center the following output on page.-->
Amount:
<input type = "text" name = "amount" id = "amount" size = "20"><br><br> <!--Amount text field.-->
Balance:
<%=(String)request.getSession().getAttribute("formattedBal")%> + "<br><br> <!--Current formatted balance shown.-->
<button name = "balButton" value = "Balance">Balance</button> <!--"Balance" button.-->
<!--Spacers.-->
<button name = "depButton" value = "Deposit">Deposit</button> <!--"Deposit" button.-->
<!--Spacers.-->
<button name = "withdrButton" value = "Withdraw">Withdraw</button> <!--"Withdraw" button.-->
</center> <!--Tag to end centering of output on page.-->
</form> <!--End of form.-->
</body>
<br>
<hr> <!--Horizontal line.-->
</html>
문제는 내가 11 줄을 가리키는 오류를 받고 있어요입니다 :
다음은 JSP의 코드입니다. 나는 기능 여부, 오류 유적을 사용하고 읽고 여부 다음과 정확히 :
HTTP 상태 500 - 타입의 예외 보고서이 요청을 이행하지 메시지 서버가 발생 설명 내부 오류() . 예외 org.apache.jasper.JasperException는 11 JSP 파일에서 : JSP 오류에 대한 클래스를 컴파일 할 수 없습니다 라인에서 발생 생성 된 서블릿 오류 /bank.jsp :! 토큰에 구문 오류 "="= org.apache.jasper.compiler.DefaultErrorHandler.javacError (DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError (ErrorDispatcher.java:328) org.apache.jasper.compiler.JDTCompiler를 기대했다. generateClass (JDTCompiler.java:397) org.apache.jasper.compiler.Compiler.compile (Compiler.java:288) org.apache.jasper.compiler.Compiler.compile (Compiler.java:267) org.apache .jasper.compiler.Compiler.compile (Compiler.java:255),515,org.apache.jasper.JspCompilationContext.compile (JspCompilationContext.java:556) org.apache.jasper.servlet.JspServletWrapper.service (JspServletWrapper.java:296) org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet 된 .java : 295) org.apache.jasper.servlet.JspServlet.service (JspServlet.java:245) javax.servlet.http.HttpServlet.service 내가 연구하고있다 (HttpServlet.java:802)
이 오류 및 관련 오류는별로 유용하지 않습니다.
오류는 "= 기호를 사용하고 있지만 오류!"라는 메시지가 표시됩니다.= 조합, 보시는 바와 같이 줄을 가리키면 처음에는 = 기호가 표시되지 않습니다.
저는 Java에 익숙하지 않습니다. 이것은 어딘가에서 간단한 실수 일 수 있습니다. 식별 할 수 있습니까?
"표준"Java 명령을 사용해야 할 때마다 JSP에서 스크립틀릿을 사용해야합니다.
또한 이러한 세션 속성과 해당 조건부 할당의 존재 여부를 확인하기 위해 설명되고 코딩 된 방법이 정확하지 않은 경우이 방법을 더 잘 수행 할 것이라고 조언하십시오.
대단히 감사합니다!