zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Log4Net学习【三】
    Log4Net学习【二】
    Log4Net学习【一】
    Asp.Net生命周期系列六
    Asp.Net生命周期系列五
    Asp.Net生命周期系列四
    Asp.Net生命周期系列三
    我为什么很烦在DB服务器上安装杀毒软件
    SQL Server 2012故障转移的looksalive check和is alive check
    如何让用户只能访问特定的数据库(MSSQL)
  • 原文地址:https://www.cnblogs.com/zhahu/p/12333692.html
Copyright © 2011-2022 走看看