2 cailei465700258 cailei465700258 于 2013.07.19 16:08 提问

求登录服务器,查看设备列表信息

自己已经写了一部分但是有错误不全面,不知道怎么去改,求大神帮忙
login.jsp
<%@page contentType="text/html; charset=GBK"%>

function validate(f){ if(!(/^\w{5,15}$/.test(f.userid.value))){ alert("用户名必须是5~15位!") f.userid.focus(); return false; } if(!(/^\w{5,15}$/.test(f.password.value))){ alert("密码必须是5~15位!") f.password.focus(); return false; } return true; }

<%request.setCharacterEncoding("GBK"); %>


















用户登录界面
用户名:
密  码:




<%if(request.getAttribute("err")!=null){ %>

<%=request.getAttribute("err") %>


<%} %>

TuserServlet.java

package org.cl.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.cl.vo.Tuser;

public class TuserServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request,response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("GBK"); // 设置中文
    String path="login.jsp";
    Tuser user = new Tuser();
    user.setlogonName(request.getParameter("logonName"));
    user.setPassword(request.getParameter("password"));
    request.getRequestDispatcher(path).forward(request, response); // 跳转

}

}

LoginJdom.java
package org.cl.jdom;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class LoginJdom {
public LoginJdom(){
String xmlfile ="xmlfile";
SAXBuilder builder = new SAXBuilder(false);
try {
Document doc = builder.build(xmlfile);
Element logon = doc.getRootElement();
List logonlist = (List) logon.getChild("logon_success");
for(Iterator iter = logonlist.iterator(); iter.hasNext();){
Element logon_success = (Element) iter.next();
String sessionID = logon_success.getAttributeValue("sessionID");
System.out.println(sessionID);
String userID = logon_success.getAttributeValue("userID");
System.out.println(userID);
String naming = logon_success.getAttributeValue("naming");
System.out.println(naming);
String isAdmin = logon_success.getAttributeValue("isAdmin");
System.out.println(isAdmin);
String priority = logon_success.getAttributeValue("priority");
System.out.println(priority);
String remain_days = logon_success.getAttributeValue("remain_days");
System.out.println(remain_days);
}
} catch (JDOMException e) {
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
}
public static void main(String args[]){
new LoginJdom();
}

}

ITuserImpl.java

package org.cl.impl;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.cl.vo.Tuser;
import org.apache.http.HttpResponse;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.DefaultHttpClient;
import org.jdom.JDOMException;
import org.omg.CORBA.NameValuePair;

public class ITuserImpl {

public static Tuser login(String logonName,String password) {
    String url("http://localhost:8080);     HttpClient httpclient = new DefaultHttpClient();
    InputStream stream = null;
    Tuser requestUser = new Tuser();
    requestUser.setlogonName(logonName);
    requestUser.setPassword(password);
    HttpGet httpget =new HttpGet("http://localhost:8080);       try{
      PostMethod post = new PostMethod( "/login.jsp" );
      NameValuePair name = new NameValuePair( "logonName" , "logonName" );
      NameValuePair pass = new NameValuePair( "password" , "password" );
      post.setRequestBody( new NameValuePair[]{name,pass});
      int status = httpclient.executeMethod(post);
      HttpResponse response = httpclient.execute(httpget);
      stream = response.getEntity().getContent();
      post.releaseConnection();

    }catch (IOException e) {

    }catch (Exception e) {

    } finally {
        try {
            if(stream != null)
                stream.close();
        } catch (Exception e) {
        }
        httpclient.getConnectionManager().shutdown();
    }
    return requestUser;
}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!