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

📄 repwd.jsp

📁 机械工业出版社的《jsp2.0动态网站开发实例指南》的源代码
💻 JSP
字号:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="law.user" %>
<%@ page import="java.sql.*" %>
<%!
	public String codeString(String s){
		String str=s;
                try{
			byte b[]=str.getBytes("ISO-8859-1");
			str=new String (b);
			return str;
		}catch(Exception e){return str;}
	}
%>
<%!
	public String formatString(String s){
		//add format way here
		
		return s;
	}
%>
<jsp:useBean id="log" class="law.user" scope="session"/>
<html>
<head><title>repwd</title></head>
<body>
<center>
<%@ include file="head.txt"%>
<%
	if(log.getLogin().equals("true")){
		if(request.getParameter("submit")!=null){
			String newpwd,newpwd2,oldpwd;
			oldpwd=request.getParameter("oldpwd");
			newpwd=request.getParameter("newpwd");
			newpwd2=request.getParameter("newpwd2");
			if(oldpwd==null)oldpwd="";
			if(newpwd==null)newpwd="";
			if(newpwd2==null)newpwd="";
			oldpwd=codeString(oldpwd);
			oldpwd=formatString(oldpwd);
			newpwd=codeString(newpwd);
			newpwd=formatString(newpwd);
			newpwd2=codeString(newpwd2);
			newpwd2=formatString(newpwd2);
			if(!newpwd.equals(newpwd2)){
				out.println("<font color=#FF0000>两次密码输入不同!");
			}
			else if(!oldpwd.equals(log.getPassword())){
				out.println("<font color=#FF0000>原密码错!");
			}
			else{
				Connection con;
				Statement sql;
				try{
					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				      	con=DriverManager.getConnection("jdbc:odbc:law","","");
				     	sql=con.createStatement();
				      	String condition="update user set password='"+newpwd+"' where id='"+log.getId()+"'";
				      	sql.executeUpdate(condition);
				      	log.setPassword(newpwd);
				      	con.close();
				      	session.invalidate();
				      	out.println("成功修改!请重新登录。");
		    		}catch(SQLException e){
		    			out.println(e);
		    		}catch(ClassNotFoundException e){
		    			out.println(e);
				}
			}	
		}
		else{
			%>
			<form action=repwd.jsp method=post name=form>
			<table width=400>
			<tr>
				<td width=150>用户:</td>
				<td width=250><font color=#FF0000><%=log.getId()%></td>
			</tr>
			<tr>
				<td width=150>原密码:</td>
				<td width=250><input type=password name=oldpwd></td>
			</tr>
			<tr>
				<td width=150>新密码:</td>
				<td width=250><input type=password name=newpwd></td>
			</tr>
			<tr>
				<td width=150>新密码:</td>
				<td width=250><input type=password name=newpwd2></td>
			</tr>
			</table>
			<input type=submit name=submit value=提交>
			<input type=reset name=reset value=重置>
			</form>
			<%
		}
	}
	else{
		out.print("<font color=#FF0000>您还没有登录。<br><a href='index.htm'>首页 </a>");
	}

%>
</center>
</body>
</html>

⌨️ 快捷键说明

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