2012-02-28 109 views
0

我有兩種不同類型的狀態欄在我的網頁上。我必須將值傳遞給此狀態欄類,以根據主頁面中的用戶選擇讓它知道要遵循的流程。如果ID = 1而不是遵循1種流程,並且ID = 2,則比遵循其他類型的流程。而且如果ID = 1和step = 2比我不得不在狀態欄中用第二步顯示一種流程風格。我堅持如何讓用戶完成1頁時從一個頁面移動到另一個頁面的流程以及移到其他地方。我如何跟蹤並在頁面頂部顯示正確的狀態欄。我怎樣才能獲得這種狀態,並在流程中進入正確的顯示狀態。到目前爲止,我已經完成了這項工作,我需要在jsp頁面中使用一些jsp內容持有者來顯示從該url連接返回的內容,並且需要將id傳遞給此類,以查看我必須遵循的流程。任何幫助將是偉大的..Java中的狀態欄

public class StatusBar 
{ 
    private static final String STATUS_URL = 'http://10.1.2.3:8080/status'; 

    private final String buffer; 
    public String toString(){ return buffer; } 

    private final String id; 
    private final String step; 


    private ProgressBar(Create create) 
    { 
     id = Create.pbid; 
     step = Create.step; 

     String response = ""; 

      Map<String, String> m = new HashMap<String, String>(); 
      m.put("id", id); 
      m.put("step", step); 

      String query = buildQuery(m); 

      URL url = new URL(STATUS_URL); 

      URLConnection uc = url.openConnection(); 
      uc.setDoOutput(true); 
      uc.setAllowUserInteraction(false); 
      uc.setConnectTimeout(5000); 
      uc.setReadTimeout(5000); 

      PrintStream ps = new PrintStream(uc.getOutputStream()); 
      ps.print(query); 
      ps.close(); 

      BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8")); 
      StringCreate sb = new StringCreate(); 
      String line; 

      while((line = br.readLine()) != null) 
      { 
       sb.append(line); 
       sb.append("\n"); 
      } 

      br.close(); 
      response = sb.toString(); 

      buffer = ""; 
    } 


    private static final String buildQuery(Map<String, String> args) throws UnsupportedEncodingException 
    { 
     StringCreate sb = new StringCreate(); 

     for(Map.Entry<String, String> entry : args.entrySet()) 
     { 
      sb.append(URLEncoder.encode(entry.getKey(), "UTF-8"));   
      sb.append('='); 
      sb.append(URLEncoder.encode(entry.getValue(), "UTF-8"));   
      sb.append('&'); 
     } 

     return sb.toString().substring(0, sb.length() - 1); 
    } 


    public static class Create 
    { 
     private String id; 
     private String step; 

     public Create(){} 

     public Create id(String val) 
     { 
      id = val; 
      return this; 
     } 

     public Create step(int val) 
     { 
      step = String.valueOf(val); 
      return this; 
     } 

     public StatusBar build() 
     { 
       return new StatusBar(this); 

     } 
    } 
} 

回答

3

從你的描述我相信你需要存儲狀態(或狀態),當用戶遍歷你的網頁。

這是HTTP Session。您可以將值存儲在您的網站的用戶會話期間。

在JSP中,您使用JSTL設置了一些會話:<c:set var="foo" value="bar" scope="session"/>並使用${foo}訪問它(檢索值返回)。

在狀態欄JSP代碼中使用它。

如果我誤解了你的問題,你可以更好地描述你真正想達到的目標,到目前爲止你嘗試過什麼,以及爲什麼你的嘗試失敗。