Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

servlet #219

wants to merge 4 commits into from

Conversation

alexpol11
Copy link

No description provided.


private void connect() {
String baseName = null;
for (int i = 0; i < 3; i++){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Лучше вынести в отдельный метод логику определения шарда
  2. 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()));

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];

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

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) {

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")){

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();

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();

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();

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Один и тот же .jsp для двух сервлетов - это не очень хорошая практика. Лучше разнести их изначально

Copy link

@arhangeldim arhangeldim left a 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"};

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"?>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну как так? В конце семестра пулл-реквест снова забит бинарниками и левыми файлами? =(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants