complete_4.java
来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 43 行
JAVA
43 行
package questions.c17;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Complete_4 extends HttpServlet {
private static String letters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public void service( HttpServletRequest req,
HttpServletResponse res )
throws ServletException, IOException
{ PrintWriter out = res.getWriter( );
res.setContentType( "text/html" );
out.println( "<HTML>" );
out.println( "<BODY>" );
out.println( "<H3>The Cookie Collector</H3>" );
// insert code to get all the cookies in the request
if ( cookies.length < 1 ) {
out.println( "<p>No cookies in request." );
} else {
out.println( "<p>The request has cookies." );
out.println( "<pre><b>Cookie Value</b>" );
}
for ( int i = 0; i < cookies.length; i++ ) {
// insert code to print each cookie's name and value
}
out.println( "</p>" );
int n = (int) ( Math.random() * 26 );
// insert code to create the new cookie,
// set its age to be removed when the browser ends,
// and add it to the response
out.println( "<p>Adding cookie:" );
out.println( "<br> " + cookie.getName() +
" " + cookie.getValue() );
out.println( "</pre></p>" );
out.println( "<p><a href=http://localhost:8080/" +
"servlet/questions.c17.Complete_4>Repeat</a>" );
out.println( "</BODY>" );
out.println( "</HEAD>" );
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?