nbsp; <td> </td>
</tr>
</tbody>
</table>
<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
<SCRIPT language=javascript>
<!--
function checkform()
{
var Checkblank = /^(s*|( )|(.))*$/;
if (Checkblank.test(dataform.username.value))
{
alert("登录名不能为空!");
return false;
}
if (Checkblank.test(dataform.userpass.value))
{
alert("密码不能为空!");
return false;
}
window.dataform.submit();
}
-->
</SCRIPT>
说明:把用户名称和用户密码提交到/tomcat/webapps/canyin/jsp/loginjudge.jsp
/tomcat/webapps/canyin/WEB-INF/classes/canyin/checkSessionBean.class (代码是相应的java 文件)
package canyin;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
public class checkSessionBean {
private boolean bolCheckPass=false;
private HttpServletRequest request = null;
public boolean checkSessionBean(HttpServletRequest request,String strSessionName,String strCheckValue){
public boolean checkSessionBean(HttpServletRequest request){
HttpSession session = request.getSession(false);
return(bolCheckPass);
if (strSessionName==null || strCheckValue==null){
return(bolCheckPass);
}else{
if (session!=null && session.getValue(strSessionName)!=null){
bolCheckPass=session.getValue(strSessionName).equals(strCheckValue);
}
return(bolCheckPass);
}
}
}
说明:检验参数传入的session 名称的数值和参数传入的字段的数值是否相等。
/tomcat/webapps/canyin/WEB-INF/classes/canyin/connXmlBean.class
代码:
package canyin;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;
public class connXmlBean {
private DocumentBuilderFactory factory=null;
private DocumentBuilder builder=null;
private Document doc=null;
public connXmlBean(){}
public String connXml(String xmlFileName){
String strExc="";
try{
factory = DocumentBuilderFactory.newInstance();
builder=factory.newDocumentBuilder();
doc=builder.parse(xmlFileName);
doc.normalize();
}catch(Exception e){
strExc=e.toString();
}
return(strExc);
}
public Document getXmlDoc(){
return(doc);
}
}
说明:打开一个指定xml 文件
/tomcat/webapps/canyin/WEB-INF/classes/canyin/writeXmlBean.class
代码:
package canyin;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import org.w3c.dom.*;
public class writeXmlBean {
public writeXmlBean(){}
public String writeXml(Document doc,String xmlFileName){
String strExc="";
try{
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(xmlFileName));
transformer.transform(source,result);
}catch(Exception e){
strExc=e.toString();
}
return(strExc);
}
}
说明:写入dom 的内容到一个指定的xml 文件。
/tomcat/webapps/canyin/jsp/loginjudge.jsp
代码:
<%-- oddWorld 餐饮管理系统(简体中文版) 2002年12月1日
copy right by joard ast
loginjudge.jsp 功能:用户身份校验,根据 /data/user.xml 文件内标示的用户不同的身份
决定转入后台管理页面,还是客户点菜页面。
--%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="javax.xml.parsers.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="canyin.*" %>
<jsp:useBean id="xmlBean" class="canyin.connXmlBean" scope="page" />
<%
session.setMaxInactiveInterval(1800);
Document doc;
NodeList users;
String strExc="";
String strUsername,strPassword;
strUsername=(String)request.getParameter("username");
strPassword=(String)request.getParameter("userpass");
//校验数据是否为空
if (strUsername=="" || strPassword=="" ){
out.println("<script language='javascript'>");
out.println("alert('用户名或密码有空值!');");
out.println("window.location.href='/index.html';");
out.println("</script>");
return;
}
xmlBean.connXml("webapps/canyin/data/users.xml");
doc=xmlBean.getXmlDoc();
try{
users =doc.getElementsByTagName("user");
for (int i=0;i<users.getLength();i++){
Element user=(Element) users.item(i);
String strAtrNameValue=user.getAttributeNode("name").getNodeValue();
String strAtrPassWordValue=user.getAttributeNode("password").getNodeValue();
String strAtrRoleValue=user.getAttributeNode("roles").getNodeValue();
if (strAtrNameValue.equals(strUsername) && strAtrPassWordValue.equals(strPassword)){
if (strAtrRoleValue.equals("admin")){
out.println("<script language='javascript'>");
out.println("alert('欢迎管理员登陆系统!');");
out.println("</script>");
//设置标示用户身份的 session(sesUserRole) ,管理员身份为 admin
session.setAttribute("sesUserRole","admin");
//跳转到管理页面
response.sendRedirect("admin/admin_rest.jsp");
return;
}else{
//设置标示用户身份的 session(sesUserRole) ,管理员身份为 user
session.setAttribute("sesUserRole","user");
//跳转到普通用户页面
response.sendRedirect(
</tr>
</tbody>
</table>
<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
<SCRIPT language=javascript>
<!--
function checkform()
{
var Checkblank = /^(s*|( )|(.))*$/;
if (Checkblank.test(dataform.username.value))
{
alert("登录名不能为空!");
return false;
}
if (Checkblank.test(dataform.userpass.value))
{
alert("密码不能为空!");
return false;
}
window.dataform.submit();
}
-->
</SCRIPT>
说明:把用户名称和用户密码提交到/tomcat/webapps/canyin/jsp/loginjudge.jsp
/tomcat/webapps/canyin/WEB-INF/classes/canyin/checkSessionBean.class (代码是相应的java 文件)
package canyin;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
public class checkSessionBean {
private boolean bolCheckPass=false;
private HttpServletRequest request = null;
public boolean checkSessionBean(HttpServletRequest request,String strSessionName,String strCheckValue){
public boolean checkSessionBean(HttpServletRequest request){
HttpSession session = request.getSession(false);
return(bolCheckPass);
if (strSessionName==null || strCheckValue==null){
return(bolCheckPass);
}else{
if (session!=null && session.getValue(strSessionName)!=null){
bolCheckPass=session.getValue(strSessionName).equals(strCheckValue);
}
return(bolCheckPass);
}
}
}
说明:检验参数传入的session 名称的数值和参数传入的字段的数值是否相等。
/tomcat/webapps/canyin/WEB-INF/classes/canyin/connXmlBean.class
代码:
package canyin;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;
public class connXmlBean {
private DocumentBuilderFactory factory=null;
private DocumentBuilder builder=null;
private Document doc=null;
public connXmlBean(){}
public String connXml(String xmlFileName){
String strExc="";
try{
factory = DocumentBuilderFactory.newInstance();
builder=factory.newDocumentBuilder();
doc=builder.parse(xmlFileName);
doc.normalize();
}catch(Exception e){
strExc=e.toString();
}
return(strExc);
}
public Document getXmlDoc(){
return(doc);
}
}
说明:打开一个指定xml 文件
/tomcat/webapps/canyin/WEB-INF/classes/canyin/writeXmlBean.class
代码:
package canyin;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import org.w3c.dom.*;
public class writeXmlBean {
public writeXmlBean(){}
public String writeXml(Document doc,String xmlFileName){
String strExc="";
try{
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(xmlFileName));
transformer.transform(source,result);
}catch(Exception e){
strExc=e.toString();
}
return(strExc);
}
}
说明:写入dom 的内容到一个指定的xml 文件。
/tomcat/webapps/canyin/jsp/loginjudge.jsp
代码:
<%-- oddWorld 餐饮管理系统(简体中文版) 2002年12月1日
copy right by joard ast
loginjudge.jsp 功能:用户身份校验,根据 /data/user.xml 文件内标示的用户不同的身份
决定转入后台管理页面,还是客户点菜页面。
--%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="javax.xml.parsers.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="canyin.*" %>
<jsp:useBean id="xmlBean" class="canyin.connXmlBean" scope="page" />
<%
session.setMaxInactiveInterval(1800);
Document doc;
NodeList users;
String strExc="";
String strUsername,strPassword;
strUsername=(String)request.getParameter("username");
strPassword=(String)request.getParameter("userpass");
//校验数据是否为空
if (strUsername=="" || strPassword=="" ){
out.println("<script language='javascript'>");
out.println("alert('用户名或密码有空值!');");
out.println("window.location.href='/index.html';");
out.println("</script>");
return;
}
xmlBean.connXml("webapps/canyin/data/users.xml");
doc=xmlBean.getXmlDoc();
try{
users =doc.getElementsByTagName("user");
for (int i=0;i<users.getLength();i++){
Element user=(Element) users.item(i);
String strAtrNameValue=user.getAttributeNode("name").getNodeValue();
String strAtrPassWordValue=user.getAttributeNode("password").getNodeValue();
String strAtrRoleValue=user.getAttributeNode("roles").getNodeValue();
if (strAtrNameValue.equals(strUsername) && strAtrPassWordValue.equals(strPassword)){
if (strAtrRoleValue.equals("admin")){
out.println("<script language='javascript'>");
out.println("alert('欢迎管理员登陆系统!');");
out.println("</script>");
//设置标示用户身份的 session(sesUserRole) ,管理员身份为 admin
session.setAttribute("sesUserRole","admin");
//跳转到管理页面
response.sendRedirect("admin/admin_rest.jsp");
return;
}else{
//设置标示用户身份的 session(sesUserRole) ,管理员身份为 user
session.setAttribute("sesUserRole","user");
//跳转到普通用户页面
response.sendRedirect(
上一页 [1] [2] [3] [4] [5] [6] 下一页