Click here to Skip to main content
15,902,939 members
Home / Discussions / Java
   

Java

 
GeneralRe: Trying to understand Puzzle4..Head First Pin
Richard MacCutchan26-Jul-13 21:57
mveRichard MacCutchan26-Jul-13 21:57 
GeneralRe: Trying to understand Puzzle4..Head First Pin
terry.schoof27-Jul-13 8:05
professionalterry.schoof27-Jul-13 8:05 
QuestionConnection String for clients machine. Pin
chdboy10-Jul-13 17:16
chdboy10-Jul-13 17:16 
AnswerRe: Connection String for clients machine. Pin
AlphaDeltaTheta10-Jul-13 20:02
AlphaDeltaTheta10-Jul-13 20:02 
QuestionRe: Connection String for clients machine. Pin
Richard MacCutchan10-Jul-13 21:10
mveRichard MacCutchan10-Jul-13 21:10 
AnswerRe: Connection String for clients machine. Pin
jschell11-Jul-13 9:00
jschell11-Jul-13 9:00 
GeneralRe: Connection String for clients machine. Pin
chdboy16-Jul-13 19:26
chdboy16-Jul-13 19:26 
QuestionSynchronize JSP Pin
lyngocquy9-Jul-13 23:15
lyngocquy9-Jul-13 23:15 
I have a I have homework about "synchronization'.
This is my demo :

NumberX.java
Java
import java.io.Serializable;
public class NumberX implements  Serializable{
    int myNumber;
    public NumberX() {}
    public NumberX(int myNumber) {this.myNumber = myNumber;}
    public int getMyNumber() {return myNumber;}
    public void setMyNumber(int myNumber) { this.myNumber = myNumber;}
    public void newNumber(){myNumber = myNumber +10;}
}




ProcessServlet.java
Java
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
       response.setContentType("text/html;charset=UTF-8");
       PrintWriter out = response.getWriter();
       try {
          int x = Integer.parseInt(request.getParameter("txtNumber"));
          NumberX n = new NumberX(x);
          n.newNumber();
          System.out.println(n.getMyNumber());
          request.setAttribute("number", n.getMyNumber());
          request.getRequestDispatcher("index.jsp").forward(request, response);
       }catch(Exception e){
           e.printStackTrace();
       }
       finally {
           out.close();
       }
   }



index.jsp
HTML
<body>
        <h1>My Test </h1>
        <%
          if(request.getAttribute("number")!=null){

          int i= (Integer)request.getAttribute("number");
        %>
        <h1 style="color:red"><%=i%></h1>
        <% } %>
        <form action="ProcessServlet" method="POST">
            <input type="text" name="txtNumber"/>
            <input type="submit" value="+"/>
        </form>
    </body>


My prolem is when I open this demo in 2 browser as 2 users .
How to synchronize 'myNumber' when :

User1 -> input(5) + clicks -> 15
User2 -> Will see 15 (<-- not refesh page )

and Otherwise .


Frown | :( Can anyone help me ,pls ?
AnswerRe: Synchronize JSP Pin
Shubhashish_Mandal10-Jul-13 2:14
professionalShubhashish_Mandal10-Jul-13 2:14 
GeneralRe: Synchronize JSP Pin
lyngocquy10-Jul-13 16:24
lyngocquy10-Jul-13 16:24 
GeneralRe: Synchronize JSP Pin
Zoidberg Why Not10-Jul-13 18:04
professionalZoidberg Why Not10-Jul-13 18:04 
QuestionMessage Closed Pin
9-Jul-13 21:02
realolap9-Jul-13 21:02 
QuestionDeveloping SaaS in Java Pin
Sarmad Hash8-Jul-13 10:19
Sarmad Hash8-Jul-13 10:19 
AnswerRe: Developing SaaS in Java Pin
Richard MacCutchan8-Jul-13 21:25
mveRichard MacCutchan8-Jul-13 21:25 
GeneralRe: Developing SaaS in Java Pin
Sarmad Hash19-Jul-13 9:28
Sarmad Hash19-Jul-13 9:28 
GeneralRe: Developing SaaS in Java Pin
Richard MacCutchan19-Jul-13 21:54
mveRichard MacCutchan19-Jul-13 21:54 
Questionnew to java - NullPointerException error Pin
Suzy McLain7-Jul-13 12:15
Suzy McLain7-Jul-13 12:15 
AnswerRe: new to java - NullPointerException error Pin
Bernhard Hiller7-Jul-13 20:46
Bernhard Hiller7-Jul-13 20:46 
AnswerRe: new to java - NullPointerException error Pin
mali_angel17-Jul-13 20:11
mali_angel17-Jul-13 20:11 
QuestionLogin process Always false..cannot find the error Pin
mali_angel3-Jul-13 18:16
mali_angel3-Jul-13 18:16 
AnswerRe: Login process Always false..cannot find the error Pin
Shubhashish_Mandal3-Jul-13 19:53
professionalShubhashish_Mandal3-Jul-13 19:53 
QuestionLogin process Always false..cannot find the error Pin
mali_angel3-Jul-13 17:22
mali_angel3-Jul-13 17:22 
AnswerRe: Login process Always false..cannot find the error Pin
mali_angel3-Jul-13 17:28
mali_angel3-Jul-13 17:28 
AnswerRe: Login process Always false..cannot find the error Pin
Shubhashish_Mandal3-Jul-13 19:40
professionalShubhashish_Mandal3-Jul-13 19:40 
GeneralRe: Login process Always false..cannot find the error Pin
mali_angel3-Jul-13 19:51
mali_angel3-Jul-13 19:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.