Can you use Java Annotations to evaluate something in a method?

I want to see if it is possible to use annotations to evaulate if a user is logged in or not. Example @AuthRequired public String myProtectedArea() { return View("view/protectedArea"); // If user is NOT authenticated, return "view/login" } As per your edit: Check this SO Post: Scanning Java annotations at runtime I'd still recommend using Spring Security for this, it's tested an

你可以使用Java Annotations来评估方法中的某些东西吗?

我想查看是否有可能使用注释来判断用户是否登录。 例 @AuthRequired public String myProtectedArea() { return View("view/protectedArea"); // If user is NOT authenticated, return "view/login" } 根据你的编辑:检查这个SO帖子: 在运行时扫描Java注释 我仍然建议使用Spring Security,它已经过测试和安全: @PreAuthorize("hasRole('ROLE_USER')") public String myProtectedArea() { return View("view/prot

Which java socket threw the Connection reset IOException?

I am trying a client-server application in Java. One of the threads in Server is responsible for listening and accepting connections from multiple clients. For every connection accepted, this thread keeps appending the new client socket object into a socket-list that it maintains. Suppose after a while the Server is connected to 10 clients. Now if the 4th client closes the connection an IOExc

哪个Java套接字抛出Connection重置IOException?

我正在尝试Java中的客户端 - 服务器应用程序。 Server中的一个线程负责监听和接受来自多个客户端的连接。 对于接受的每个连接,此线程都会将新客户端套接字对象附加到它所维护的套接字列表中。 假设一段时间后服务器连接到10个客户端。 现在,如果第4个客户端关闭连接,则会出现IOException,并显示“Connection reset”消息。 有没有办法让服务器找出哪个套接字(10个套接字)抛出了这个异常? (在这种情况下是第四个插座

HttpURLConnection connection reset error handling

I have server client java application running on version SE6. Messaging between server and client is via http protocol. Generally this application was running well but lately I start to see some "connection reset" errors on client side logs. I thought it can be because of keep alive and disabled it but error still there. Here is the client side error log. java.net.SocketException:

HttpURLConnection连接重置错误处理

我有版本SE6上运行的服务器客户端Java应用程序。 服务器和客户端之间的消息传递是通过http协议。 通常这个应用程序运行良好,但最近我开始在客户端日志中看到一些“连接重置”错误。 我认为这可能是因为保持活力和禁用它,但仍然存在错误。 这是客户端错误日志。 java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:208) at java.net.SocketInputStream.read(Soc

SocketException Handling

I can`t understand something simple. I have a class that handles the socket input. I have a catch-clause: public class EntryPoint implements Runnable { private Socket socket = null; private BufferedReader br = null; // receives data from the destination ... public void run() { String command = null; // buffer for holding one request from com

SocketException处理

我不能理解简单的事情。 我有一个处理socket输入的类。 我有一个catch语句: public class EntryPoint implements Runnable { private Socket socket = null; private BufferedReader br = null; // receives data from the destination ... public void run() { String command = null; // buffer for holding one request from command line StringReader

Send a 0 byte using DataOutputStream?

I'm creating an server for an existing client. This client reads input from server using a socket and DataInputStream. It checks for end of server message using: byte c = in.readByte(); if( c == 0) { //the end. On the server i'm using a serversocket and DataOutputStream to send message to client: out.write(bytes[]) How can i send a 0 byte so that the client knows it is the end of th

使用DataOutputStream发送一个0字节?

我正在为现有的客户端创建一个服务器。 该客户端使用套接字和DataInputStream从服务器读取输入。 它使用以下命令检查服务器消息的结尾: byte c = in.readByte(); if( c == 0) { //the end. 在服务器上,我正在使用serversocket和DataOutputStream发送消息给客户端: out.write(bytes[]) 我如何发送一个0字节,以便客户端知道它是消息的结尾? 当然你只想要一个长度为1的数组,单个元素设置为0? out.write(new byte[]{0})

Java : Alpha Beta Pruning

I'm trying to implement a Mini Max & Alpha Beta Pruning algorithm in java, for some reason the Pruning algorithm does not perform a single prune although the algorithm visits 24,911 Nodes. The GameNode values are initiated to -99 for MaxNodes and 99 for MinNodes aswell as Alpha=-99 Beta=99. The game is called "Nim" and the value is either 1 or -1, win or lose, no score. Any

Java:Alpha Beta修剪

我试图在java中实现Mini Max和Alpha Beta修剪算法,由于某些原因,Pruning算法不会执行单个修剪,尽管该算法访问了24,911个节点。 GameNode值对于MaxNodes以99开始,对于MinNodes以及在Alpha = -99 Beta = 99开始为99。 游戏被称为“Nim”,其值为1或-1,输赢或不输。 任何想法为什么修剪不会发生? 这里是修剪的代码: public static int Prune(GameNode n){ if(n.getSuccessors()==null) return n.GetUtil

tic tac toe using alpha beta prunning in java

I am trying to play tic tac toe using iterative Alpha-Beta prunning, I have one second limit for a move but for some reason it doesnt work well. I modified the regular alpha-beta code so instead of returning alpha or beta, it returns a state (which is the board with the next move) Each time I create children I update their depth. But again for some reason I keep losing and I see that my alp

在java中使用alpha beta prunning的tic tac脚趾

我正在尝试使用迭代Alpha-Beta prunning玩tic tac脚趾,我有一个移动的第二个限制,但由于某种原因,它不能很好地工作。 我修改了常规的alpha-beta代码,而不是返回alpha或beta,它返回一个状态(这是下一步移动的板子) 每次我创建孩子时,我都会更新他们的深度。 但由于某种原因,我仍然失败,我发现我的alpha测试版并没有看到最好的举动。 这是我的代码: 外部循环: while (watch.get_ElapsedMilliseconds() <

Java minmax algorithm returning null move and failing to correctly undo moves

Here is the code for my minmax algorithm: private static void minmax(){ Move move = max(4, true, null); //System.out.println(move); board.makeMove(move.getFromPoint(), move.getToPoint()); } private static Move max(int depth, boolean player, Move passedMove){ if(depth == 0) return passedMove.setScore(board.boardVal()); Move max = new Move(Integer.MIN_VALUE); for(int i = 0

Java minmax算法返回空移动,并且无法正确地撤消移动

这里是我的minmax算法的代码: private static void minmax(){ Move move = max(4, true, null); //System.out.println(move); board.makeMove(move.getFromPoint(), move.getToPoint()); } private static Move max(int depth, boolean player, Move passedMove){ if(depth == 0) return passedMove.setScore(board.boardVal()); Move max = new Move(Integer.MIN_VALUE); for(int i = 0; i < boar

Java tictactoe problems with minmax algorithm

i want to implement the MinMax algorithm for tictactoe. I have two methods min() and max() and a evaluation method, but it doesn't works. For example when i call max(9); Field[bestCol][bestRow]='O'; min(8); Field[bestCol][bestRow]='X'; in the main function the result is OX- --- --- But the best Move for Player 'X' is to put the 'X'

用minmax算法的Java tictactoe问题

我想为tictactoe实现MinMax算法。 我有两个方法min()和max()和一个评估方法,但它不起作用。 例如,当我打电话 max(9); Field[bestCol][bestRow]='O'; min(8); Field[bestCol][bestRow]='X'; 在主要功能的结果是 OX- --- --- 但是对于玩家'X'来说,最好的举动是把'X'放在中间。 这里是我的代码没有评估方法: static char[][] Field = { { '-', '-', '-' },

Java Connect 4 MinMax Algorithm

EDIT: I don't know why somebody links me a TicTacToe as duplicate for my question, there isn't even a MinMax-Algorithm in it. Currently i'm working on a Connect4 game against the computer which should use the MinMax-Algorithm. Before that, we wrote a TicTacToe which also uses the MinMax, but i'm not sure how to change my old algorithm to match the Connect4-Game :/. In TicTacTo

Java Connect 4 MinMax算法

编辑:我不知道为什么有人将我的TicTacToe链接为我的问题的重复,甚至没有MinMax算法。 目前,我正在对应使用MinMax算法的计算机进行Connect4游戏。 在此之前,我们写了一个TicTacToe,它也使用MinMax,但我不知道如何改变我的旧算法以匹配Connect4-Game:/。 在TicTacToe中,我评估了每一个可能的举措,我写的胜利条件,它运作良好,但现在它不会与我的新条件。 我makeAMove等工作正常! 这些是我的旧条件和TicTacToe的M