//package com.demo;
//
//import java.io.*;
//import javax.servlet.*;
//import javax.servlet.http.*;
//import javax.servlet.annotation.WebServlet;
//
//@WebServlet("/secondservlet")  // 修改映射路径
//public class SecondServlet extends HttpServlet {
//    private static final long serialVersionUID = 1L;
//    
//    @Override
//    public void doGet(HttpServletRequest request, HttpServletResponse response)
//            throws ServletException, IOException {
//        doPost(request, response);
//    }
//    
//    @Override
//    public void doPost(HttpServletRequest request, HttpServletResponse response)
//            throws ServletException, IOException {
//        response.setContentType("text/html;charset=UTF-8");
//        PrintWriter out = response.getWriter();
//        
//        Student stud = (Student)request.getAttribute("stud");
//        
//        out.println("<html><body>");
//        out.println("<center>");
//        
//        if (stud != null) {
//            out.println("学号：" + stud.getSno() + "<br>");
//            out.println("姓名：" + stud.getName() + "<br>");
//        } else {
//            out.println("错误：未能获取到学生信息<br>");
//        }
//        
//        out.println("<a href=\"/helloweb/input.html\">返回输入页面</a>");
//        out.println("</center>");
//        out.println("</body></html>");
//        out.flush();
//        out.close();
//    }
//}


package com.demo;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;

@WebServlet("/SecondServlet")
public class SecondServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        // 获取ServletContext中的Student对象
        ServletContext context = getServletContext();
        Student student = (Student) context.getAttribute("student");
        
        // 设置响应内容类型
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        // 输出学生信息
        out.println("<html><body>");
        out.println("<h2>学生信息</h2>");
        out.println("<p>学号：" + student.getSno() + "</p>");
        out.println("<p>姓名：" + student.getName() + "</p>");
        out.println("<a href=\"input.html\">返回输入页面</a>");
        out.println("</body></html>");
    }
}
