JSP实现成语接龙
首页:
<%--
Created by IntelliJ IDEA.
User: zdd
Date: 2019/11/18
Time: 10:15
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>成语接龙首页</title>
</head>
<body>
四字成语接龙<br>
你输入的成语为:
<%
String s = (String)application.getAttribute("message");
if(s!=null){
out.println(s);
}else{
out.println("还没有成语,请输入:<br>");
}
%>
<form action="jielong.jsp" method="post">
<br>
输入成语:<input type="text" name="mess"/><br>
<input type="submit" value="提交"/>
</form>
</body>
</html>
处理页面
<%--
Created by IntelliJ IDEA.
User: zdd
Date: 2019/11/18
Time: 10:21
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>jielong.jsp</title>
</head>
<body>
<%!
String message = "";
ServletContext application;
synchronized void sendmessage(String s){
application= getServletContext();
message = message+s+"--->";
application.setAttribute("message",message);
}
%>
<%
request.setCharacterEncoding("UTF-8");
String content = request.getParameter("mess");
sendmessage(content);
out.println("你的成语"+content+"已经提交");
response.setHeader("refresh","3;chengyu.jsp");
%>
</body>
</html>
运行结果: