-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
servlet #219
base: master
Are you sure you want to change the base?
servlet #219
Conversation
|
||
private void connect() { | ||
String baseName = null; | ||
for (int i = 0; i < 3; i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Лучше вынести в отдельный метод логику определения шарда
- switch-case внутри for - выглядит странно
append("track17?"). //db name | ||
append("user=track_student&"). //login | ||
append("password=7EsH.H6x"); //password | ||
connectionsMap.put(new Integer(i), DriverManager.getConnection(url.toString())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new Integer() ? Зачем?
} | ||
|
||
private Connection returnDbconnection(String username) throws IllegalArgumentException{ | ||
char firstLetter = username.toLowerCase().toCharArray()[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше String::charAt(int index)
public long store(Message msg) { | ||
try { | ||
Connection connection = returnDbconnection(msg.ownerLogin); | ||
PreparedStatement statement = connection.prepareStatement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
statement и resultSet нужно закрывать в finally блоке. Касается запросов во всем коде
|
||
|
||
}catch (SQLException | IllegalArgumentException e) { | ||
if (e instanceof IllegalArgumentException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не надо так. Сделайте 2 отдельных catch блока
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
Map<String, String[]> params = req.getParameterMap(); | ||
|
||
if (params.containsKey("limit")){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше в константы вынести
Map<String, String[]> params = req.getParameterMap(); | ||
|
||
if (params.containsKey("limit")){ | ||
ConversationService conv = new ConversationService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Надо создать внутри конструктора, а не при каждом запросе
|
||
if (params.containsKey("username") && params.containsKey("text")) { | ||
if (!req.getParameter("username").equals("")) { | ||
ConversationService conv = new ConversationService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тоже создать в конструкторе сервлета
Map<String, String[]> params = req.getParameterMap(); | ||
|
||
if (params.containsKey("limit") && params.containsKey("username")){ | ||
ConversationService conv = new ConversationService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
то же
|
||
List<Message> msgUserHistory = conv.getByUser(req.getParameter("username"), Long.parseLong(req.getParameter("limit"))); | ||
req.setAttribute("msgList", msgUserHistory); | ||
req.getRequestDispatcher("/history.jsp").forward(req, resp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Один и тот же .jsp для двух сервлетов - это не очень хорошая практика. Лучше разнести их изначально
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сервлет вроде рабочий, засчитаю на 10 баллов
import java.util.Map; | ||
|
||
public class UserHistory extends HttpServlet { | ||
private String[] param = {"limit", "username"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ключи параметров лучше вынести в константы
@@ -0,0 +1,38 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну как так? В конце семестра пулл-реквест снова забит бинарниками и левыми файлами? =(
No description provided.