| | |
Can anyone make this code work?
![]() |
•
•
Join Date: Oct 2007
Posts: 23
Reputation:
Solved Threads: 0
This is my HTML File:
And this is my servlet:
Without getter and setter methods the code is working fine..Can anyone find and solve the issue?
Expecting your Reply
Dave.
html Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> function validateCatalogId(){ var req=init(); function init(){ if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } } var catalogId=document.getElementById("catalogId"); req.open("POST", "validateForm", true); req.onreadystatechange=processRequest; req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.send("catalogId="+ encodeURIComponent(catalogId.value)); function processRequest(){ if(req.readyState==4){ if(req.status==200){ processResponse(); } } } function processResponse(){ var xmlMessage=req.responseXML; } } </script> </head> <body> <h1>Form for Catalog Entry</h1> <form name="validationForm" action="validateForm" method="post"> <div id="catalogId" name="catalogId"> </div> <table> <tr><td>Journal:</td><td><input type="text" size="20" id="journal" name="journal"></td> </tr> <tr><td>Publisher:</td><td><input type="text" size="20" id="publisher" name="publisher"></td> </tr> <tr><td><input type="button" onclick="validateCatalogId();" value="Create Catalog" id="submitForm" name="submitForm"></td> </tr> </table> </form> </body> </html>
And this is my servlet:
java Syntax (Toggle Plain Text)
import java.io.*; import java.sql.*; import javax.naming.InitialContext; import javax.servlet.*; import javax.servlet.http.*; public class FormServlet extends HttpServlet { private String catalogId =null; private String journal=null; private String publisher= null; public void setCatalogId(String catalogId) { this.catalogId= catalogId; } public String getCatalogId() { return catalogId; } public void setJournal(String journal) { this.journal= journal; } public String getJournal() { return journal; } public void setPublisher(String publisher) { this.publisher= publisher; } public String getPublisher() { return publisher; } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Obtain value of Catalog Id field to ve validated. String catalogId = request.getParameter("catalogId"); String journal = request.getParameter("journal"); String publisher = request.getParameter("publisher"); // set headers before accessing the Writer response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); if(request.getParameter("catalogId") != null) { setCatalogId(request.getParameter("catalogId")); } else { setCatalogId(" "); } if(request.getParameter("journal") != null) { setJournal(request.getParameter("journal")); } else { setJournal(" "); } if(request.getParameter("publisher") != null) { setPublisher(request.getParameter("publisher")); } else { setPublisher(" "); } // then write the response // If result set is empty set valid element to true response.getWriter().write("<catalog>" + "<catalogId>+getCatalogId()+</catalogId>" + "<journal>+getJournal()+</journal>" + "<publisher>+getPublisher()+</publisher>" + "</catalog>"); } }
Expecting your Reply
Dave.
Last edited by peter_budo; Jul 25th, 2008 at 10:06 am. Reason: Keep It Organized - please use [code] tags
Are you running this on Tomcat server?
What are you trying to achieve?
Are there any errors?
What are you trying to achieve?
Are there any errors?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- need help to make this program work (C++)
- Why won't this code work? (VB.NET)
- How do I work around this? - virtual templates (C++)
- Please help me make this script work in Netscape (JavaScript / DHTML / AJAX)
- I could use some help with ofstream (C++)
- Anyone make a recycle bin W/ SMB? (*nix Software)
- beans bound property: getNewValue() doesn't work out. Code attached (Java)
- code repeatedly 2 ask user 4 a password until correct (=Java) but cant c wots wrong. (Java)
- stuck with definition (C++)
Other Threads in the IT Professionals' Lounge Forum
- Previous Thread: best joomla tutorial
- Next Thread: From Communication to IT?
| Thread Tools | Search this Thread |
1gbit amazon answers archive british broadband business businessprocesses career carrier censorship cern china cio collectiveintelligence connectivity consumer consumers corporateearnings css datatransfer debtcollectors dictionary digg digital ebay ecommerce email employment environment facebook government grid high-definition hottub infodelivery infotech intel internet interview ipod isp japan kindle lhc library malware marketing mit moonfruit news onlineshopping php piracy piratebay pope porn program r&d religion remoteworking research retail schools security sex shopping simple skype smallbusiness smb sms socialmedia socialnetworking software softwareengineer spam speed spending startrek statistics stocks study stumbleupon survey tabletpc technology touch-screen touchscreen training twitter uk vbulletin videoinprint voips web webdesign webdeveloper windows words






