📄 teacher.jsp
字号:
<%@ page contentType="text/html; charset=GB2312"%>
<%@ page language="java" import="java.sql.*"%>
<jsp:directive.page import="news.sql_data"/>
<HTML>
<HEAD>
<TITLE>teacher.jsp</TITLE>
<link rel="stylesheet" href="m_style.css" type="text/css">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function btnClick(type){
var fm=document.form1
if(type=='add'){
fm.c.value=1;
return true;
}else if(type=='edt'){
fm.c.value=2;
return true;
}else if(type=='del'){
fm.c.value=3;
return true;
}
}
function login(){
window.location="login.jsp"
}
function redirect(){
window.location="student.jsp"
}
function radio() {
l=document.getElementsByName("radio")
for(i=0;i<l.length;i++) {
if(l[i].checked)
document.getElementById("id").value=l[i].value
}
}
</SCRIPT>
<jsp:useBean id="db" scope="session" class="news.sql_data"/>
<BODY>
<%!
public String Bytes(String str)
{
try{
String str_1=str;
byte[] str_2=str_1.getBytes("ISO8859-1");
String bytes=new String(str_2);
return bytes;
}catch(Exception ex){
System.out.println("中文乱码解决问题出错"+ex.getMessage());
}
return null;
}
%>
<% try{
String parm = request.getParameter("c");
if(parm==null)
{
parm="";
}
// request.setCharacterEncoding("GBK");
String id=request.getParameter("id");
String name=(String ) session.getAttribute("name");
String password=(String )session.getAttribute("password");
String roleid=(String )session.getAttribute("roleid");
if (parm.equals("1")) {
String mysql = "insert into news values" + "(" + id+",'"
+ name + "','" + password
+ "'," + roleid + ")";
db.executeUpdate(mysql);
}else if (parm.equals("2")) {
String mysql = "update news set name='"
+ name + "',password='" + password + "',roleid="
+ roleid + " where id=" + id ;
db.executeUpdate(mysql);
} else if(parm.equals("3")){
String mysql = "delete from news where id="
+ id ;
db.executeUpdate(mysql);
}
ResultSet rs=db.executeQuery("select news.id,news.name,role.role from news,role where news.roleid=role.id and roleid=2");
%>
<%
if(session.getAttribute("name")==null){%>
<script language="JavaScript">
window.location="login.jsp"
</script>
<%}
else
{%><table>
<tr>
<td>
用户名:<%=session.getAttribute("name")%>
<input type="button" value="重新登录" onclick="login()">
</td>
</tr>
</table>
<%}
%>
<table border="1" align="center" >
<tr><td align="center" colspan="4">学生列表</td></tr>
<tr bgcolor="d1d1ff">
<th>ID</th><th>姓 名</th><th>角 色</th><th>选择</th>
</tr>
<%
while(rs.next()){
String a=rs.getString(1);
%>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><input type="radio" id="radio" name="radio" onclick="radio()" value="<%=a%>"></td>
</tr>
<%}
rs.close();
db.closeStmt();
db.closeConn();
}catch(Exception exc1){
System.out.println("在执行数据库访问时发生了错误!");
exc1.printStackTrace();
}
%>
</table>
<center>
<form id="form1" name="form1" method="post" action="teacher.jsp">
<table>
<tr>
<td>学生 I D:</td>
<td><input type="text" name="id" value="" > </td>
</tr>
<tr>
<td>学生成绩: </td>
<td><input type="text" name="cj" value="" > </td>
</tr>
<tr>
<td colspan ="2">
<input type="hidden" name="c" id="c">
<input type="submit" name="edt" value="修改成绩" onclick="btnClick('edt')">
<input type="button" onClick="redirect()";" value="个人信息" >
<input type="button" name="ret" value="返回" onclick="history.go(-1)">
<input type="button" onClick="window.opener = '';window.close();" value="关闭" >
</td>
</tr>
</table>
</form>
</center>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -