Navigation Bar

Wednesday, January 23, 2002

java debug code

Alternative approach
=====================
public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception {
    
    String symbol = request.getParameter("symbol");
    System.out.println("Symbol received: " + symbol);
    
    String stockName = getStockNameFromDB(symbol);
    System.out.println("Stock name found: " + stockName);
    
    // Just return the stock name as plain text
    response.setContentType("text/plain;charset=UTF-8");
    response.setHeader("Cache-Control", "no-cache");
    
    PrintWriter out = response.getWriter();
    out.print(stockName);
    out.flush();
    
    return null;
}


function processStateChange(req) {
    console.log("ReadyState:", req.readyState);
    
    if (req.readyState == 4) { // Complete
        if (req.status == 200) { // OK response
            console.log("Ajax response:", req.responseText);
            
            // Directly set the input field value
            var stockNameInput = document.getElementById('sname');
            if (stockNameInput) {
                stockNameInput.value = req.responseText;
                console.log("Stock name updated to:", req.responseText);
            } else {
                console.error("Input field 'sname' not found!");
            }
            
        } else {
            alert("Problem with server response:\n " + req.statusText);
        }
    }
}

No comments:

Post a Comment