jsp页面刷新原理???jsp+servlet 15
我做一个网上订餐系统,我用bean发送订单,服务器确认后回复,在sevlet里建一个serversocket接受服务器给的price,在init()函数里。但之前已经显示...
我做一个网上订餐系统,我用bean发送订单,服务器确认后回复,在sevlet里建一个serversocket接受服务器给的price,在init()函数里。但之前已经显示了回复的页面,我想通过刷新得到price,但总是为空。怎样能得到price.我验证过了servlet可以收到返回的price.
public class PizzaInterface extends HttpServlet {
ServletToPizza p = new ServletToPizza();
String line;
public void init() {
try{
ServerSocket ss= new ServerSocket(5678);
while(true){
MultiUser mu= new MultiUser(ss.accept());
mu.start();
}
}catch(IOException ex){
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher rd= request.getRequestDispatcher("/Welcome.html");
rd.forward(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//send value
p.setIPC(InetAddress.getLocalHost());
String[] values = request.getParameterValues("order");
p.setOrder(values);
String l= request.getParameter("location");
p.setIPS(l);
p.setAddress(l);
String l1= request.getParameter("username");
p.setName(l1);
String l2= request.getParameter("phone");
p.setPhone(l2);
String l3= request.getParameter("post");
p.setPost(l3);
String l4= request.getParameter("mail");
p.setMail(l4);
p.send();
ArrayList<String> a= new ArrayList<String>();
a.add(p.getName()+p.getAddress()+p.getPrice());
request.getSession().setAttribute("a",p.getPrice());
request.getSession().setAttribute("valiCode",a.get(a.size()-1));
request.getRequestDispatcher("/DisplayMessage.jsp").forward(request,response);
}
public class MultiUser extends Thread{
private Socket client;
public MultiUser(Socket c){
this.client=c;
}
public void run(){
try{
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out=new PrintWriter(client.getOutputStream());
String line = in.readLine();
p.setPrice(line);
out.println("yse,the client has received");
out.flush();
SimpleDateFormat format = new SimpleDateFormat( "yyyy-M-d kk:m:ss");
String s = format.format(new Date());
p.setDate(s);
in.close();
out.close();
client.close();
}catch(IOException e){
}
}
}
}
这是servlet的代码
请哪位大牛帮我解答一下!!! 急啊!!!
我的servlet调用bean 的socket传输数据,然后开启一个serversocket(5678) 来接受数据,是这样的。 展开
public class PizzaInterface extends HttpServlet {
ServletToPizza p = new ServletToPizza();
String line;
public void init() {
try{
ServerSocket ss= new ServerSocket(5678);
while(true){
MultiUser mu= new MultiUser(ss.accept());
mu.start();
}
}catch(IOException ex){
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher rd= request.getRequestDispatcher("/Welcome.html");
rd.forward(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//send value
p.setIPC(InetAddress.getLocalHost());
String[] values = request.getParameterValues("order");
p.setOrder(values);
String l= request.getParameter("location");
p.setIPS(l);
p.setAddress(l);
String l1= request.getParameter("username");
p.setName(l1);
String l2= request.getParameter("phone");
p.setPhone(l2);
String l3= request.getParameter("post");
p.setPost(l3);
String l4= request.getParameter("mail");
p.setMail(l4);
p.send();
ArrayList<String> a= new ArrayList<String>();
a.add(p.getName()+p.getAddress()+p.getPrice());
request.getSession().setAttribute("a",p.getPrice());
request.getSession().setAttribute("valiCode",a.get(a.size()-1));
request.getRequestDispatcher("/DisplayMessage.jsp").forward(request,response);
}
public class MultiUser extends Thread{
private Socket client;
public MultiUser(Socket c){
this.client=c;
}
public void run(){
try{
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out=new PrintWriter(client.getOutputStream());
String line = in.readLine();
p.setPrice(line);
out.println("yse,the client has received");
out.flush();
SimpleDateFormat format = new SimpleDateFormat( "yyyy-M-d kk:m:ss");
String s = format.format(new Date());
p.setDate(s);
in.close();
out.close();
client.close();
}catch(IOException e){
}
}
}
}
这是servlet的代码
请哪位大牛帮我解答一下!!! 急啊!!!
我的servlet调用bean 的socket传输数据,然后开启一个serversocket(5678) 来接受数据,是这样的。 展开
4个回答
展开全部
既然你只想刷新价格
那么就把价格当做一个单独的servlet
用jquery去异步调用就行了
那么就把价格当做一个单独的servlet
用jquery去异步调用就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这段代码是使用了comet技术的。但是好像没写全。你在服务器端建了个5678的端口socket,客户端也应该用js写个socket。这样服务器端把消息写到这个socket。客户端就能拿到消息做处理了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-11-21
展开全部
request.getSession().setAttribute(
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询