JSP实现成语接龙

 功能:

  • 判断头尾是否一致
  • 判断是否是四字成语
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
	<form action="soli.jsp" method="post">
		输入四字成语:<input type="text" name="ciyu">
		<input type="submit"value="提交">
	</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%
String cyu = request.getParameter("ciyu");
int flag = 0;
int ting = 0;
if(cyu.length() != 12){
	out.println("请输入正确的四字成语!"+"<br>");
	 ting =1;
}else{
	//out.println("成语已经提交!"+"<br>");
	flag++;
}


String tou1 = request.getParameter("ciyu");
String tou = request.getParameter("ciyu");
String wei = request.getParameter("ciyu");
String tag ="";
String to ="";
String we ="";
String str = "";
if(flag==1){
	tou1 =new String(tou1.getBytes("ISO-8859-1"),"utf-8");
    tag = tou1.substring(3);
//	out.println(tag);
	flag++;
}

if(flag>1){    
    	tou =new String(tou.getBytes("ISO-8859-1"),"utf-8");
    	wei =new String(wei.getBytes("ISO-8859-1"),"utf-8");
    	 to = tou.substring(0,1);
    	 we = wei.substring(3);
    }
	
	
		
	ArrayList mation = (ArrayList) session.getAttribute("mation");
	if (mation == null) {
		mation = new ArrayList();
		session.setAttribute("mation", mation);
	}
	String ciyu = request.getParameter("ciyu");
	if(ciyu != null&&mation.size()>0){
		for(int i=0;i<mation.size();i++){
			str = mation.get(i).toString();
			str = str.substring(3);
//			out.println(str);
		}
		if(str.equals(to)){
			ciyu = new String(ciyu.getBytes("ISO-8859-1"),"utf-8");
			mation.add(ciyu);
			out.println("成语已经提交!"+"<br>");	
		}else{
			out.println("成语首尾不匹配!");
		}
		if(str.equals(to)){
			for(int i =0;i<mation.size();i++){
				out.println(mation.get(i)+"-->");
			}
		}
	}
	if (ciyu != null&&mation.size()==0) {
		ciyu = new String(ciyu.getBytes("ISO-8859-1"),"utf-8");
		mation.add(ciyu);
		out.println("成语已经提交!"+"<br>");	
			out.println(mation.get(0)+"-->");
	
	}
//	for(int i =0;i<mation.size();i++){
//		out.println(mation.get(i)+"-->");
//	}
	
 
	
%>
<br>
<a href ="idiom.jsp">继续输入成语</a>
</body>
</html>

 

 

全部评论

相关推荐

笑死&nbsp;不是哥们离校了我真要睡街了&nbsp;加上还有几w的贷款&nbsp;不接受我准备去当三和大神
梦想是成为七海千秋:没事,hr这下就有底气了,下次遇到一个不接受的就说,你看,人家这学历都接受了,你凭什么不接受
点赞 评论 收藏
分享
迟缓的斜杠青年巴比Q了:简历被投过的公司卖出去了,我前两天遇到过更离谱的,打电话来问我有没有意向报班学Java学习,服了,还拿我学校一个学长在他们那报班学了之后干了华为OD当招牌
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务