时间:2021-07-01 10:21:17 帮助过:19人阅读
1.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP ‘1.jsp‘ starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <form name="form1" method="post" action="2.jsp"> <p>name= <label for="textfield"></label> <input type="text" name="myname" id="textfield"> </p> <p>class= <label for="textfield2"></label> <input type="text" name="myclass" id="textfield2"> </p> <p> <input type="submit" name="button" id="button" value="提交"> </p> </form> </body> </html>
2.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <jsp:useBean id="myjdbc01" scope="page" class="com.zss.www.DBConn"/> <% request.setCharacterEncoding("utf-8"); String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; String myname=request.getParameter("myname"); String myclass=request.getParameter("myclass"); %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP ‘001.jsp‘ starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <%=myname%><br> <%=myclass%><br> <% String insertsql="insert into information(name,class) values(‘"+myname+"‘,‘"+myclass+"‘)"; myjdbc01.doInsert(insertsql); myjdbc01.close(); %> </body> </html>
3.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="java.sql.*" %> <%@ page import="com.mysql.jdbc.*" %> <jsp:useBean id="myjdbc01" scope="page" class="com.zss.www.DBConn"/> <% request.setCharacterEncoding("utf-8"); String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP ‘001.jsp‘ starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% String sql="select * from information"; ResultSet rs = myjdbc01.doSelect(sql); while (rs.next()) { out.println(rs.getString(1)); out.println(rs.getString(2)); } %> </body> </html>
运行截图如下:
1.jsp:
MySQL下:
独立运行3.jsp:
WEB(JSP)下的JDBC操作
标签:project trace generated otf cat strong png encoding while