Java 服务器中,如何根据两个参数(用户名和密码)判断这个用户的session 是否存在?即这个

Java 服务器中,如何根据两个参数(用户名和密码)判断这个用户的session 是否存在?即这个,第1张

服务器有session对象,sessiongetattribute( "currentUser")
如何为null 说明没有登录,否则已经登录,当然你登录成功的时候必须
sessionsetattribute("currentUser",user ) 把当前用户保存到session会画总

当然需要,因为前端的JS验证代码如果在用户端浏览器被禁用了,那么就不会执行该js代码进行验证,也就相当于没有做非空验证,如果这时候将数据直接在服务器端使用,那么情况可想而知;一句话,永远不要轻易相信客户提供给你的数据;当初我们的培训导师说过,你只要把使用你软件的客户当做傻瓜,思考的问题自然多于常人。

边界层与阻力系数,球体运动通过边界层和外界发生了密切关系。因为边界层内的空气自球面向外转速越来越小,每层之间就会发生相对运动和相对摩擦。这些摩擦将会把球体的能量消耗掉,从而减慢了球体的运动。这就是流体中摩擦阻力的由来。在高速流动中,球体外的空气会不断地分离(边界层分离,boundary layer separation)。>properties文件中未注释的中文不要直接用中文表示,利用jdk自带的命令native2ascii 转换例如然后就可以用\u5728\u8fd9\u91cc\u8f93\u5165\u4e2d\u6587\u540e\u56de\u8f66来替换“在这里输入中文后回车”在properties文件中的位置

Server代码

package comjavacodegeeksandroidandroidsocketserver;
 
import javaioBufferedReader;
import javaioIOException;
import javaioInputStreamReader;
import javanetServerSocket;
import javanetSocket;
import androidappActivity;
import androidosBundle;
import androidosHandler;
import androidutilLog;
import androidwidgetTextView;
 
public class Server extends Activity
{
    private ServerSocket serverSocket;
    private Handler updateConversationHandler;
    private Thread serverThread = null;
    private TextView text;
    public static final int SERVERPORT = 6000;
 
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
 
        superonCreate(savedInstanceState);
        setContentView(Rlayoutmain);
 
        text = (TextView) findViewById(Ridtext2);
 
        updateConversationHandler = new Handler();
 
        thisserverThread = new Thread(new ServerThread());
        thisserverThreadstart();
 
    }
 
    @Override
    protected void onStop()
    {
        superonStop();
        try
        {
            serverSocketclose();
        }
        catch (IOException e)
        {
            eprintStackTrace();
        }
    }
 
    private class ServerThread implements Runnable
    {
 
        public void run()
        {
            Socket socket = null;
            try
            {
                serverSocket = new ServerSocket(SERVERPORT);
            }
            catch (IOException e)
            {
                eprintStackTrace();
            }
            while (!ThreadcurrentThread()isInterrupted())
            {
                try
                {
                    socket = serverSocketaccept(); // TODO
 
                    CommunicationThread commThread = new CommunicationThread(socket);
                    new Thread(commThread)start();
                }
                catch (IOException e)
                {
                    Logi("liu", "socketaccept()失败");
 
                    eprintStackTrace();
                }
            }
        }
    }
 
    private class CommunicationThread implements Runnable
    {
        private Socket clientSocket;
        private BufferedReader input;
 
        public CommunicationThread(Socket clientSocket)
        {
            thisclientSocket = clientSocket;
 
            Logi("liu", "获取到了client的Socket");
 
            try
            {
                thisinput = new BufferedReader(new InputStreamReader(thisclientSocketgetInputStream())); // TODO
            }
            catch (IOException e)
            {
                Logi("liu", "input获取失败");
                eprintStackTrace();
            }
        }
 
        public void run()
        {
            while (!ThreadcurrentThread()isInterrupted())
            {
                try
                {
                    String read = inputreadLine(); // TODO
                    Logi("liu", read);
                    updateConversationHandlerpost(new updateUIThread(read));
                }
                catch (IOException e)
                {
                    Logi("liu", "input读取失败");
                    eprintStackTrace();
                }
            }
        }
    }
 
    private class updateUIThread implements Runnable
    {
        private String msg;
 
        public updateUIThread(String str)
        {
            thismsg = str;
        }
 
        @Override
        public void run()
        {
            textsetText(textgetText()toString() + "Client Says: " + msg + "\n");
        }
 
    }
 
}

2 Client代码:

package comjavacodegeeksandroidandroidsocketclient;
 
import javaioBufferedWriter;
import javaioIOException;
import javaioOutputStreamWriter;
import javaioPrintWriter;
import javanetInetAddress;
import javanetSocket;
import javanetUnknownHostException;
import androidappActivity;
import androidosBundle;
import androidutilLog;
import androidviewView;
import androidwidgetEditText;
 
public class Client extends Activity
{
    private Socket socket;
    private static final int SERVERPORT = 4000;
    private static final String SERVER_IP = "10022";
 
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        superonCreate(savedInstanceState);
        setContentView(Rlayoutmain);
 
        new Thread(new ClientThread())start();
    }
 
    public void onClick(View view)
    {
        try
        {
            EditText et = (EditText) findViewById(RidEditText01);
            String str = etgetText()toString();
 
            Logi("liu", "点击按钮");
 
            PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socketgetOutputStream())), true); // TODO
            outprintln(str);
        }
        catch (Exception e)
        {
            Logi("liu", "write失败");
            eprintStackTrace();
        }
    }
 
    class ClientThread implements Runnable
    {
 
        @Override
        public void run()
        {
            try
            {
                InetAddress serverAddr = InetAddressgetByName(SERVER_IP);
                socket = new Socket(serverAddr, SERVERPORT);
            }
            catch (UnknownHostException e1)
            {
                e1printStackTrace();
            }
            catch (IOException e1)
            {
                e1printStackTrace();
            }
        }
    }
}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10282236.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-07
下一篇 2023-05-07

发表评论

登录后才能评论

评论列表(0条)

保存