📄 showuserdetail.java
字号:
/*
*
*/
import java.io.*;
import java.text.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*/
public class ShowUserDetail extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
HtmlOut htmlOut = new HtmlOut (response);
// 得到名字和口令
String name,pass;
Person person = new Person();
person.setName (CommonMethods.GetUserName(request));
pass = CommonMethods.GetUserPass (request);
if( person.getName ()==null || (!person.checkPassword(pass))||(!person.IsSuperMan ()) )
{
htmlOut.setErrorID (htmlOut.USER_NEED_LOGIN,"",
"用户不存在或用户密码错误或用户无权限","/manage/index.htm");
htmlOut.outHtml();
return;
}
name= person.getName ();
TemplateList tempList=CommonMethods.getShowUserInfoTemplate ();
SingleTemplate st;
st = tempList.searchTemplate ("ROOT");
if(st==null)
{
htmlOut.setErrorID (htmlOut.SINGLE_TEMPLATE_NOTFIND ,"",
"无法找到模板","ShowUserDetail");
htmlOut.outHtml();
return ;
}
String username=request.getParameter ("user");
String sPage=request.getParameter ("page");
int nPage=0;
if ((sPage==null)||(sPage.trim ().length ()==0))
nPage=0;
else{
try{
nPage=Integer.valueOf (sPage).intValue ();
}catch(Exception e){
nPage=0;
System.out.println ("get the page error:"+e.toString ());
}
}
if ((username==null)||(username.trim ().length ()==0))
{
htmlOut.setErrorID (htmlOut.USER_NEED_LOGIN,"",
"用户不存在","/UserAdmin?page="+nPage);
htmlOut.outHtml();
return;
}
//替换模板文件
int nKey = st.getKeyNum ();
String sKey= new String ();
DBOperater DB1=new DBOperater ("person");
String QueryString;
QueryString="select firstname,email,gender,birthyear,birthmonth,birthday,"
+"education,jobfunction,state,phone,mobile,BP,city,zip,passid,address,mark,joinDate"
// +"education,jobfunction,state,phone,mobile,BP,city,zip,passid,address,mark"
+" from person where username='"+username+"'";
//
ResultSet rs=DB1.executeQuery (QueryString);
int n=0;
try{
if(rs!=null)
{
while (rs.next())
{
String test=rs.getString (1);
for(int i=0;i<nKey;i++){
htmlOut.addString (st.getStringAt (i));
sKey = st.getKeyAt (i);
if( sKey.compareTo("cgi-path")==0 )
htmlOut.addString (CommonMethods.sHostNameCGI);
if( sKey.compareTo ("username")==0)
htmlOut.addString (username);
if (sKey.compareTo ("页数")==0)
htmlOut.addString (nPage+"");
if ((sKey.compareTo ("firstname")==0)&&(rs.getString (1)!=null))
htmlOut.addString (rs.getString (1));
if ((sKey.compareTo ("email")==0)&&(rs.getString (2)!=null))
htmlOut.addString (rs.getString (2));
if ((sKey.compareTo ("gender")==0)&&(rs.getString (3)!=null))
htmlOut.addString (rs.getString (3));
if ((sKey.compareTo ("birthyear")==0)&&(rs.getString (4)!=null))
htmlOut.addString (rs.getString (4)+"-");
if ((sKey.compareTo ("birthmonth")==0)&&(rs.getString (5)!=null))
htmlOut.addString (rs.getString (5)+"-");
if ((sKey.compareTo ("birthday")==0)&&(rs.getString (6)!=null))
htmlOut.addString (rs.getString (6));
if ((sKey.compareTo ("education")==0)&&(rs.getString (7)!=null))
htmlOut.addString (rs.getString (7));
if ((sKey.compareTo ("jobfunction")==0)&&(rs.getString (8)!=null))
htmlOut.addString (rs.getString (8));
if ((sKey.compareTo ("state")==0)&&(rs.getString (9)!=null))
htmlOut.addString (rs.getString (9));
if ((sKey.compareTo ("phone")==0)&&(rs.getString (10)!=null))
htmlOut.addString (rs.getString (10));
if ((sKey.compareTo ("mobile")==0)&&(rs.getString (11)!=null))
htmlOut.addString (rs.getString (11));
if ((sKey.compareTo ("BP")==0)&&(rs.getString (12)!=null))
htmlOut.addString (rs.getString (12));
if ((sKey.compareTo ("city")==0)&&(rs.getString (13)!=null))
htmlOut.addString (rs.getString (13));
if ((sKey.compareTo ("zip")==0)&&(rs.getString (14)!=null))
htmlOut.addString (rs.getString (14));
if ((sKey.compareTo ("passid")==0)&&(rs.getString (15)!=null))
htmlOut.addString (rs.getString (15));
if ((sKey.compareTo ("address")==0)&&(rs.getString (16)!=null))
htmlOut.addString (rs.getString (16));
if ((sKey.compareTo ("joindate")==0)&&(rs.getString (18)!=null))
htmlOut.addString (rs.getString (18));
if (sKey.compareTo ("用户级别")==0)
{
if (rs.getInt (17)==1)
htmlOut.addString ("超级用户");
else if(rs.getInt (17)==2)
htmlOut.addString ("管理员");
else
htmlOut.addString ("一般用户");
}
}
htmlOut.addString (st.getEndString());
//out.println (st.getEndString());
htmlOut.outHtml();
}
}
}
catch(Exception e){
System.out.println("get userdetail error:"+e.toString ());
return;
}
return;
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -