<!--JSP指令-->
<%@
page language="java"
import="java.util.*"
contentType="text/html;charset=utf-8"
%>
<html>
<head>
<title>你好,JSP</title>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
</head>
<body>
<!--小脚本-->
<%
int i;
for(i=0;i<4;i++){
out.println("你好,JSP<br/>");
}
smile();
%>
<!--JSP表达式-->
说了<%=i%>次你好
<!--JSP声明-->
<%!
void smile(){
javax.servlet.jsp.JspWriter out = null;
tyr
out.print("很高兴");
}
%>
</body>
</html>
********
<!--JSP指令-->
<%@
page language="java"
import="java.util.*"
contentType="text/html;charset=utf-8"
%>
<html>
<head>
<title>菱形</title>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
</head>
<body>
<%
int l=10;
for(int i=1;i<=l;i++){int star=l-i+1;int endd=l+i-1;
for(int j=1;j<2*l;j++){
if(j>=star&&j<=endd&&(j-star)%2==0){
out.print("<span style=\"color:blue;\">*</span>");
}else{out.print(" ");}
}
out.print("<br/>");
}
for(int i=l-1;i>0;i--){int star=l-i+1;int endd=l+i-1;
for(int j=1;j<2*l;j++){
if(j>=star&&j<=endd&&(j-star)%2==0){
out.print("<span style=\"color:red;\">*</span>");
}else{out.print(" ");}
}
out.print("<br/>");
}
%>
</body>
</html>
* * * * * *
<!--登陆页面-->
<%@
page language="java"
import="java.util.*"
contentType="text/html;charset=utf-8"
%>
<html>
<head>
<title>登陆</title>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
</head>
<body>
<div>
<form name="reg" method="post" action="ctrl.jsp">
<table>
<tr><td>姓名</td><td><input name="uname" type="text"></td></tr>
<tr><td>密码</td><td><input name="upass" type="password"></td></tr>
<tr><td>身份</td><td><input name="ub" type="radio" value="1"/>普通<input name="ub" type="radio" value="2"/>管理员</td></tr>
<tr><td colspan="2">三分钟内面登陆<input name="cks" type="checkbox"></td></tr>
<tr><td colspan="2"><input type="submit"></td></tr>
</table>
</form>
</div>
</body>
</html>
* * * * * *
<!--中间控制页面-->
<%@
page language="java"
import="java.util.*"
contentType="text/html;charset=utf-8"
%>
<html>
<head>
<title>Ctrl</title>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
<%
String ub=request.getParameter("ub");
String uname=request.getParameter("uname");
RequestDispatcher rd=request.getRequestDispatcher("admin.jsp");
//创建cookie
Cookie cks=new Cookie("uname",uname);
cks.setMaxAge(3*60);
response.addCookie(cks);
if(ub.equals("1")){//ub代表用户身份
session.setAttribute("USER",uname);
response.sendRedirect("normal.jsp");
}
if(ub.equals("2")){
session.setAttribute("ADMIN",uname);
rd.forward(request,response);
}
%>
</head>
</html>
* * * * * *
<!--普通用户-->
<%@
page language="java"
import="java.util.*"
contentType="text/html;charset=utf-8"
%>
<html>
<head>
<title>普通用户</title>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
</head>
<body>
<%
//String uname=request.getParameter("uname");
String uname=(String)session.getAttribute("ADMIN");
if(uname==null){//cookie中空
Cookie [] acks=request.getCookies();
for(int i=0;i<acks.length;i++){
if(acks[i].getName().equals("uname")){
uname=acks[i].getValue();
break;
}
}
}
if(uname==null){//uname还为空,重定向
response.sendRedirect("login.jsp");
}
%>
您好会员:<%=uname%>
</body>
</html>
* * * * * *
<!--JSP指令-->
<%@
page language="java"
import="java.util.*"
contentType="text/html;charset=utf-8"
%>
<html>
<head>
<title>管理员</title>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
</head>
<body>
<%
//String uname=request.getParameter("uname");
String uname=(String)session.getAttribute("ADMIN");
if(uname==null){
response.sendRedirect("login.jsp");
}
%>
您好管理员:<%=uname%>
</body>
</html>
*******
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Fstate {// 第一个Statement
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");// 加载驱动
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@192.168.0.28:1521:orcl", "zhangguobin",
".");// 创建JDBC连接
Statement st=conn.createStatement();//创建Statement对象
//System.out.println(st.execute("insert into roads values('r0002','10001','白河路')"));//执行sql的insert语句
// ResultSet rs=st.executeQuery("select * from roads");//执行sql的select语句
// while(rs.next()){//操作结果集
// System.out.println(rs.getString("road_name"));
// }
String sql="insert into roads values(?,?,?)";
PreparedStatement pst=conn.prepareStatement(sql);//创建PreparedStatement对象
pst.setString(1, "r0003");
pst.setString(2, "10001");
pst.setString(3, "白河路");
System.out.println(pst.execute());
st.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}