΢ Ͷ ^ ھ

cba决赛的赛程 :JSPFf̲”Α

cba㶫 www.axwwg.com  •rg2019-09-09 09:00:33   ߣ   ҪuՓ(0)

ČҷJSPFf̲”Αľwa҅w
OӋһweb appÿήaһ30ԃȵĔo5ΙC׌͑œy@

ČҷJSPFf̲”Αľwa҅w

OӋһweb appÿήaһ30ԃȵĔo5ΙC׌͑œy@֣

1͑µĔֱȮaĔֵtʾˡ
2͑µĔֱȮaĔֵСtʾСc

Œ˾^PeGame OveroęC

JSPa

<%@ page language="java" contentType="text/html; charset=UTF-8"
 pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "//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 result=(String)request.getAttribute("result");
  if(result!=null){
   out.write("<font color='red'>"+result+"'</font>");
  }
%>

<% 
 Integer times=(Integer)request.getAttribute("times");
  if(times!=null){
   out.write("߀"+(5-times)+"ΙC!");
  }
%>
<br/>
<form action="/zxz/zxz" method="POST">
 ՈݔĔ(20)<input type="text" name="Lucy" /><br/>
 <%
  if(times!=null){
 %>
   <input type="hidden" name="times" value="<%=times %>"/>
 <%  
  }
 %>
 <input type="submit" value="" />
</form>
</body>
</html>

Servleta

package hah;

import java.io.IOException;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class zxz
 */
@WebServlet("/zxz")
public class zxz extends HttpServlet {
 private static final long serialVersionUID = 1L;

 int answer;
 public void newGame() {
  Random random=new Random();
  answer=random.nextInt(20);
 }
 public zxz() {
  newGame();
 }
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  response.setContentType("text/html;charset=utf-8");
  String lucyStr=request.getParameter("Lucy");
  Integer lucyNb=null;
  System.out.println("𰸣"+answer);
  if(!lucyStr.equals("")) {
   lucyNb=Integer.parseInt(lucyStr);
  }
  Integer times=1;

  String timeStr=request.getParameter("times");
  if(timeStr!=null&&!timeStr.equals("")) {
   times=Integer.parseInt(timeStr)+1;
  }
  if(times<5) {
   String result="";
   if(lucyNb>answer) {
    result="";   
   }else if(lucyNb<answer) {
    result="С";
   }else if(lucyNb==answer) {
    result="";
    times=null;
   }
   request.setAttribute("times", times);
   request.setAttribute("result", result);
  }else {
   newGame();
   response.getWriter().write("ΑY<a href='"+request.getContextPath()+"/One.jsp'>فһ</a>");
   return;
  }
  request.getRequestDispatcher("/One.jsp").forward(request, response);
 }


 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  doGet(request, response);
 }

}

Y

a. ʹØ˺hidden[ʽfÑlF Áӛ䛴Δ 磺

<input type="hidden" name="times" value="<%=times %>"/>

b. ServletÁD͈߉݋aJSPÁչʾ
c. request.getParameter(Lucy)ڄtnullֵַ
d DЃɷNʽ һD ַҪĿ+jspservlet

һDlrequestֱַӌjspservlet ҪĿ ĿjspservletǰҪӡ/ Ȼλ

<form action="/zxz/zxz" method="POST">
//Dl
request.getRequestDispatcher("/One.jsp"). 
forward(request, response);

ϾDZĵȫϣҵČWҲϣҶ֧_֮

ܸdȤ:

  • jsp+servletF”Α

P

  • JSPFf̲”Α

    JSPFf̲”Α

    ČҷJSPFf̲”Αľwa҅w OӋһweb appÿήaһ30ԃȵĔo5ΙC׌͑œy@
    2019-09-09
  • jsp+servletF”Α

    jsp+servletF”Α

    jsp+servletF”ΑҪõservletsessionHttpServletResponseеsendRedirect() step1͑LˢgetNumber.jsprS
    2019-09-09
  • JSPF½Ϣ

    JSPF½Ϣ

    JSPͨ^JSFϢʽɸҪ޸@߅ֻһεʾԶx˃ɗlϢЧ JSP <%@ page language="java" i
    2019-09-09
  • JSPFꑿԼӰЧ

    JSPFꑿԼӰЧ

    ČҷJSPFꑿԼӰЧľwa҅w f˼JSPꑿ˼҂JSP½һdivȻ
    2019-09-09
  • phpý亯\Mַȡ

    phpý亯\Mַȡ

    ČYphpý亯oҹ҅w£ M M range(start,end) һM,ֵstart_ʼ,һֱendY
    2019-09-09
  • phpý亯\Mַȡ

    phpý亯\Mַȡ

    ČYphpý亯oҹ҅w£ M M range(start,end) һM,ֵstart_ʼ,һֱendY
    2019-09-09
  • phpý亯\Mַȡ

    phpý亯\Mַȡ

    ČYphpý亯oҹ҅w£ M M range(start,end) һM,ֵstart_ʼ,һֱendY
    2019-09-09
  • phpý亯\Mַȡ

    phpý亯\Mַȡ

    ČYphpý亯oҹ҅w£ M M range(start,end) һM,ֵstart_ʼ,һֱendY
    2019-09-09
  • phpý亯\Mַȡ

    phpý亯\Mַȡ

    ČYphpý亯oҹ҅w£ M M range(start,end) һM,ֵstart_ʼ,һֱendY
    2019-09-09
  • shell_OracleДrˢµftp

    shell_OracleДrˢµftp

    F󣺌oracleеĔʌrͬijftpԱǰˑܶrftpĿȡ ӹ_惦^Ȼshel
    2019-09-09