<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <div> <h1>Q. 100 + 200 = ?</h1> </div> <div> <a href="to.jsp?ans=100">100</a> <a href="to.jsp?ans=200">200</a> <a href="to.jsp?ans=300">300</a> <a href="to.jsp?ans=400">400</a> <a href="to.jsp?ans=500">500</a> </div> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String numstr = request.getParameter("ans"); int ans = 0; if(numstr != null && !numstr.equals("")){ ans = Integer.parseInt(numstr); } %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <%if(ans == 300){ %> <div><h1><%out.println("응답결과");%></h1></div> <%out.println("정답");%> <%}else{ %> <div><h1><%out.println("응답결과");%></h1></div> <%out.println("정답이 아닙니다.");%> <%} %> </body> </html>
ans의 값이 300일 경우
ans의 값이 300이 아닐경우