2017-04-13 7 views
0

入力数はセッション数で取得します。正確な入力のNUMを得るために、私はコードを持って、これまで入力数を取得するセッション数:

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    // TODO Auto-generated method stub 

    String pro=request.getParameter("inputs"); 
    HttpSession session=request.getSession(true); 
    Integer Counter = 
       (Integer)session.getAttribute("Counter"); 
    session.setAttribute("input", inp); 
    if(Counter==null){ 
     Counter=0; 
     println((String)session.getAttribute("input") +""+Counter); 
    } 
    if((session.getAttribute("input").equals(inp))){ 
     Counter++; 
     println(session.getAttribute("input")+"" +Counter); 
    } 
+0

出力はどこに行くのですか?ブラウザなどに戻る? – stdunbar

+0

ちょうどサーブレットは出力を示しています – user245548

+0

はどこにも行きません – user245548

答えて

0

私は次のようにもう少し何かをするだろう:これはPOSTを必要とする

public void doPost(HttpServletRequest request, HttpServletResponse response) { 
    String word = request.getParameter("word"); 

    HttpSession httpSession = request.getSession(); 

    Integer numRequestsForWord = (Integer)httpSession.getAttribute(word); 

    if(numRequestsForWord == null) 
     numRequestsForWord = 1; 
    else 
     numRequestsForWord += 1; 

    httpSession.setAttribute(word, numRequestsForWord); 

    if(numRequestsForWord == 1) 
     System.out.println(word); 
    else 
     System.out.println(word + "(" + numRequestsForWord + ")"); 
} 

- 私はよく分からないどのように」このメソッドを呼び出します。

+0

ありがとう@stdunbarしかし、私は同じセッションで他の値を表示する必要があります。例えば、apple(2)、juice(3)、beans(5)のように – user245548

+0

あなたはあなたですか? – user245548

関連する問題