Help coderanch get a
new server
by contributing to the fundraiser

harmeet bawa

Greenhorn
+ Follow
since Sep 12, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by harmeet bawa

In the Servlets response I have some XML like:
<customer><customerName>the name</customerName></customer>

THis comes back to the Javascript and it generates a select box with the customerNames returned back.
17 years ago
JSP
"Perhaps you're trying to ask how to handle the XML that the servlet returns to that HTML and Javascript you have in the browser"


Ok I think thats what it is. what am I doing wrong here then?
17 years ago
JSP
I want to take the result of the servlet, parse the XML response from the servlet and display the values parsed from the XML response on the JSP
17 years ago
JSP
Thanks you Paul.
Could you please tell me the way to go here. I got what you said and that is what I exactly want.
In the servlet I have formed the response. Now I leave it here. But in the JSP what I am doing is, I need to read the HTTP Response from the servllet and then I parse the XML and display all the relevant info on the JSP. How exactly do I do this?

Thanks again,
Harmeet
17 years ago
JSP
Thanks for the prompt response. This is an AJAX transcation. The JSP code excerpt is here:
function getTheRequest() {
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
isIE = true;
return new ActiveXObject("Microsoft.XMLHTTP");
}
}


function doComplete() {
if(idField.value == "") {
clearTable();
} else {
searchType = document.getElementById("searchBy");
completeTable.style.visibility = "visible";

var url = "AutoComplete?action=complete&id=" + escape(idField.value) + "&searchBy=" + escape(searchType.value);
req = getTheRequest();
req.open("GET", url, true);
req.onreadystatechange = processRequest;
req.send(null);
}
}


function processRequest() {
if(req.readyState == 4) {
if(req.status == 200) {
parseMessages(req.responseXML);
}
}
}


function parseMessages(responseXML) {

clearTable();
var search = responseXML.getElementsByTagName("search")[0];
if(search.childNodes.length > 0) {
} else {
clearTable();
}

for(loop = 0; loop < search.childNodes.length; loop++) {
var customer = search.childNodes[loop];
var companyName = customer.getElementsByTagName("companyName")[0];
appendCompany(unescape(companyName.childNodes[0].nodeValue));
}
}


function appendCompany(companyName) {
var row;
row = document.createElement("option");
row.className = "popupRow";
row.setAttribute("value", companyName);
row.appendChild(document.createTextNode(companyName));
completeTable.appendChild(row);
}


function clearTable() {
if(completeTable) {
completeTable.style.visible = false;
for(loop = completeTable.childNodes.length - 1; loop >= 0; loop--) {
completeTable.removeChild(completeTable.childNodes[loop]);
}
}
}

The HTTP response adds the xml string and then I forward back to the JSP. Here it is reading the xml string in addition to the HTML from the JSP being added to the response. Can I know a way to prevent this? I hope I made it a bit more clearer this time.
17 years ago
JSP
Hi all,
I have a servlet where i am forming this xml string and passing it back to the JSP.
The servlet code:

package wwxchange;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;


import wwxchange.utility.*;
import wwxchange.beans.*;


public class AutoComplete extends HttpServlet {

private ServletContext context;

//Initialize global variables
public void init(ServletConfig config) throws ServletException {
this.context = config.getServletContext();
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String searchBy = request.getParameter("searchBy");
String id = request.getParameter("id");
String action = request.getParameter("action");
boolean added = false;
ArrayList list = new ArrayList();
StringBuffer sb = new StringBuffer();

HttpSession session = request.getSession();
UserAcctBean user = (UserAcctBean) session.getAttribute("currentuser");
AirbillBean ab = (AirbillBean) session.getAttribute("currentshipment");
String loginID = user.getLoginID();
String accountNbr = user.getAcctNum();

if(id != null)
id = id.trim().toLowerCase();

list = ab.getNamesForAutoComplete(id, accountNbr, searchBy);

for(int i=0;i<list.size();i++) {
sb.append("<customer>");
sb.append("<companyName>" + list.get(i) + "</companyName>");
sb.append("</customer>");
added = true;
}
if(added) {
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<search>" + sb.toString() + "</search>");
} else {
//nothing to show
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}

context.getRequestDispatcher("/CreateShipment.jsp").forward(request, response);


}

//Clean up resources
public void destroy() {
}
}


When I access this response from the JSP, it is adding the JSP code from the CreateShipment.jsp page to ehich i am forwarding the respose to in the response body along with the xml string.

I cant commit the response in the servlet coz i am writing to the writer. That gives me an IllegalStateException. What is it that i am missing here?

Thanks in advance.
harmeet
[ January 07, 2007: Message edited by: Bear Bibeault ]
17 years ago
Hi all,
I have a servlet where i am forming this xml string and passing it back to the JSP.
The servlet code:



When I access this response from the JSP, it is adding the JSP code from the CreateShipment.jsp page to ehich i am forwarding the respose to in the response body along with the xml string.

I cant commit the response in the servlet coz i am writing to the writer. That gives me an IllegalStateException. What is it that i am missing here?

Thanks in advance.
harmeet

[BSouther: Added UBB CODE tags]
[ January 05, 2007: Message edited by: Ben Souther ]
17 years ago
JSP
This is what I am doing:

I have a JSP in whhich I display rows for a table (picking the data up from the database). This code for generating the table rows is in a java class. After its displayed, I want to make a select on a row and delete it. What I am tryin to do here is that I am generationg an id and linking that id with each row. This id comes back as a request parameter to the same jsp. I am trying to get the ids value in a javascript fiunction on the jsp. But it dosesn seem to work.
18 years ago
JSP
i am generating the html in a java class to keep the colde clean. its just like i go and look uo in the database for the entried already present for the use in the java class and then spit them out on the jsp.
18 years ago
JSP
thnx guys. any suggestions to do what I am doin?
[ January 24, 2006: Message edited by: harmeet bawa ]
18 years ago
JSP
this is what i am trying to do:

I generate the html for a jsp in a java class. For that I am appending the html to a string buffer.
eg.
stringbuffer.append("<input type='text' name='name' value='<jsp:getProperty name=\"beannabe\" property=\"propertyname\" />'>");

when I print the value of the stringbuffer on the jsp it is just displaying the '<jsp:getProperty name=\"beannabe\" property=\"propertyname\" />' as is and not getting the value of the property form the bean.
What is it that I am doing wrong here?

Thnx in advance
Harmeet
[ January 24, 2006: Message edited by: Bear Bibeault ]
18 years ago
JSP
i have tried using gmails sinetfactory to snd out the emails. i did it from 3 systems here in my office. the code:

import com.jscape.inet.smtpssl.*;
import com.jscape.inet.email.*;
import com.sun.net.ssl.internal.ssl.Provider;
import com.sun.net.ssl.TrustManager.*;

public class SmtpGmail {

public static void main(String[] args) {
SmtpSsl smtp = null;

// gmail username - CHANGE THIS
String username = "yourusername@gmail.com";

// gmail password - CHANGE THIS
String password = "yourpassword";

// address to send mail to - CHANGE THIS
String to = "xyz@xyz.com";
try {
// create a new SmtpSsl instance connecting securely via port 465 using implicit SSL
smtp = new SmtpSsl("smtp.gmail.com",465);

// establish secure connection
smtp.connect();

// login using gmail account details
smtp.login(username,password);

// create new email message
EmailMessage message = new EmailMessage();
message.setTo(to);
message.setFrom(username);
message.setSubject("Sending email via Gmail SMTP");
message.setBody("This is the body of the message");

// send message
smtp.send(message);

// disconnect
smtp.disconnect();
} catch(Exception e) {
// capture any exception and print to console
e.printStackTrace();
}
}
}

this thing worked here. but then i logged in to a remote server and tried the same thing. this is the response:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/net/ssl/Trust
Manager
at com.jscape.inet.ipclientssl.SecureSocket.getTrustAllManagers(Unknown
Source)
at com.jscape.inet.ipclientssl.SecureSocket.<init>(Unknown Source)
at com.jscape.inet.ipclientssl.IpClientSsl.connect(Unknown Source)
at com.jscape.inet.smtpssl.SmtpSsl.connect(Unknown Source)
at SmtpGmail.main(SmtpGmail.java:24)

if i can get some help on this it will be wonderful. cant get why it is complaining here abt a missing class.

thanks
harmeet
sending out an email is not an issue at this time. i have used javamail api as well as the jakarta commons email to send the email out. Well for myself i can use my local smtp server. but if i am sending this programs class file ot other ppl to send out emails, its not going to work for them. is there a way in wondows where i can find out a users smtp server and plug it in my program, so that they can send out the email.

thanks in advance
harmeet
my program runs a couple of routines, downloads some files over ftp. after successful completion of all the steps the last stage in the program is to send out an email to the users account that there were no errors. how do i go about doing this?

thanks
harmeet
This is what I am looking for exactly. I have a java program that connects to our smtp server. I sent out the class file to other people so that they can use it to send out emails. This dosent seem to work. So is it that I need to find out their smpt servers and then send out emails using their smtp servers. And if I can do that, how do I do it in windows.wither xp or nt.

thanks
harmeet