⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usebeanjsp_0002ejsp_jsp.java

📁 java 数据库编程实例 经过反复调试 保证可以运行 是学习java网络编程的绝佳资料
💻 JAVA
字号:
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;


public class useBeanJsp_0002ejsp_jsp extends HttpJspBase {

    // begin [file="/useBeanJsp.jsp";from=(13,0);to=(13,64)]
    // end

    static {
    }
    public useBeanJsp_0002ejsp_jsp( ) {
    }

    private static boolean _jspx_inited = false;

    public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
    }

    public void _jspService(HttpServletRequest request, HttpServletResponse  response)
        throws java.io.IOException, ServletException {

        JspFactory _jspxFactory = null;
        PageContext pageContext = null;
        HttpSession session = null;
        ServletContext application = null;
        ServletConfig config = null;
        JspWriter out = null;
        Object page = this;
        String  _value = null;
        try {

            if (_jspx_inited == false) {
                synchronized (this) {
                    if (_jspx_inited == false) {
                        _jspx_init();
                        _jspx_inited = true;
                    }
                }
            }
            _jspxFactory = JspFactory.getDefaultFactory();
            response.setContentType("text/html; charset=GBK");
            pageContext = _jspxFactory.getPageContext(this, request, response,
            			"", true, 8192, true);

            application = pageContext.getServletContext();
            config = pageContext.getServletConfig();
            session = pageContext.getSession();
            out = pageContext.getOut();

            // HTML // begin [file="/useBeanJsp.jsp";from=(0,48);to=(1,0)]
                out.write("\r\n");

            // end
            // begin [file="/useBeanJsp.jsp";from=(1,2);to=(10,0)]
                
                /**
                 * Title:			JSP页面使用JavaBean连接数据库
                 * Description:			教学示范
                 * Copyright:			Copyright (c) 2003
                 * Company:			北京师范大学计算机系
                 * @author			孙一林
                 * @version			1.0
                 */
            // end
            // HTML // begin [file="/useBeanJsp.jsp";from=(10,2);to=(12,0)]
                out.write("\r\n<html>\r\n");

            // end
            // HTML // begin [file="/useBeanJsp.jsp";from=(12,30);to=(13,0)]
                out.write("\r\n");

            // end
            // begin [file="/useBeanJsp.jsp";from=(13,0);to=(13,64)]
                dbbean.dbBean dbBean = null;
                boolean _jspx_specialdbBean  = false;
                 synchronized (session) {
                    dbBean= (dbbean.dbBean)
                    pageContext.getAttribute("dbBean",PageContext.SESSION_SCOPE);
                    if ( dbBean == null ) {
                        _jspx_specialdbBean = true;
                        try {
                            dbBean = (dbbean.dbBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "dbbean.dbBean");
                        } catch (ClassNotFoundException exc) {
                             throw new InstantiationException(exc.getMessage());
                        } catch (Exception exc) {
                             throw new ServletException (" Cannot create bean of class "+"dbbean.dbBean", exc);
                        }
                        pageContext.setAttribute("dbBean", dbBean, PageContext.SESSION_SCOPE);
                    }
                 } 
                if(_jspx_specialdbBean == true) {
            // end
            // begin [file="/useBeanJsp.jsp";from=(13,0);to=(13,64)]
                }
            // end
            // HTML // begin [file="/useBeanJsp.jsp";from=(13,64);to=(15,0)]
                out.write("\r\n<head>\r\n");

            // end
            // begin [file="/useBeanJsp.jsp";from=(15,2);to=(17,0)]
                
                  String tableName = request.getParameter("tableName");
            // end
            // HTML // begin [file="/useBeanJsp.jsp";from=(17,2);to=(18,7)]
                out.write("\r\n<title>");

            // end
            // begin [file="/useBeanJsp.jsp";from=(18,10);to=(18,19)]
                out.print(tableName);
            // end
            // HTML // begin [file="/useBeanJsp.jsp";from=(18,21);to=(21,0)]
                out.write("表中数据</title>\r\n</head>\r\n<body bgcolor=\"#FFFFFF\" text=\"#000000\">\r\n");

            // end
            // begin [file="/useBeanJsp.jsp";from=(21,2);to=(52,0)]
                
                  if (tableName.equals("studentbase"))
                  {
                    out.println("<h2 align=center>学生基本信息表中的数据</h2>");
                  }
                  else if (tableName.equals("studentaddress"))
                  {
                    out.println("<h2 align=center>学生地址表中的数据</h2>");
                  }
                  else
                  {
                    out.println("<h2 align=center>选课信息表中的数据</h2>");
                  }
                  ResultSet rs = dbBean.getTableData(tableName);
                  ResultSetMetaData rsData = rs.getMetaData();
                  out.println("<table width=75% border=1 align=center><tr>");
                  for(int i=1; i<=rsData.getColumnCount(); i++)    //输出字段名
                  {
                    out.println("<td>" + rsData.getColumnLabel(i) + "</td>");
                  }
                  out.println("</tr>");
                  while(rs.next())                                 //输出表中数据
                  {
                    out.println("<tr>");
                    for(int i=1; i<=rsData.getColumnCount();i++)
                    {
                      out.println("<td>" + rs.getString(i) + "</td>");
                    }
                    out.println("</tr>");
                  }
                  out.println("</table>");
            // end
            // HTML // begin [file="/useBeanJsp.jsp";from=(52,2);to=(55,0)]
                out.write("\r\n</body>\r\n</html>\r\n");

            // end

        } catch (Throwable t) {
            if (out != null && out.getBufferSize() != 0)
                out.clearBuffer();
            if (pageContext != null) pageContext.handlePageException(t);
        } finally {
            if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -