Servlet can't get the xmlhttp post request

hi! i'm new to xmlhttp..i am trying to make a widget that will show the gps info of the device and after that the gps info will be save to mysql..why i can't save the gps info to the database here is my code..
//function sending request to servlet
function callback1( result){
var latitude = result.ReturnValue.Latitude;
var longitude = result.ReturnValue.Longitude;
var req = null;
try {
req = new XMLHttpRequest();
if (typeof req.overrideMimeType != "undefined") {
req.overrideMimeType("text/xml");
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
} else {
alert("Error");
var url = "?d=""&latitude="+latitude"&longitude="+longitude;
req.open("POST","http://localhost:8080/GPS/location",true);
req.setRequestHeader("longitude",+longitude);
req.setRequestHeader("latitude",+latitude);
req.send();
} catch (ex) {
alert(ex);
location.java
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String connectionURL="jdbc:mysql://localhost:3306/loc";
Connection connection;
try{
Enumeration headerNames=request.getHeaderNames();
while(headerNames.hasMoreElements()){
String headerName=(String)headerNames.nextElement();
String headerValue=request.getHeader(headerName);
pw.println(headerName);
pw.println(headerValue);
Class.forName("org.gjt.mm.mysql.Driver");
connection=DriverManager.getConnection(connectionURL,"root","1234");
PreparedStatement pst = connection.prepareStatement("insert into loc values(?,?)");
pst.setString(1,headerName);
pst.setString(2,headerValue);
int i = pst.executeUpdate();
if(i!=0){
pw.println("<br>Record has been inserted");
else{
pw.println("failed to insert the data");
catch (Exception e){
pw.println(e);
--i tried to run my java servlet and it can save already the default headername and value to my repository...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

abcdefhhij wrote:
hi! i'm new to xmlhttp...Then stop right there. Don't write Javascript code which uses XMLHttpRequest, use one of the Javascript libraries (such as JQuery) which wrap it in a layer of code which deals with all of the horrendous issues with browser incompatibilities.
It's obvious to me that you have been reading old tutorials. Not only the one about XMLHttpRequest -- which as I said, nobody should be coding to these days -- but also the one about MySQL where it uses a class name for the MySQL JDBC driver which has been outdated for I would guess at least five years. Reading tutorials is an excellent idea, but at least try to find newer tutorials.

Similar Messages

  • Servlet can't get the correct timezone in NAS

    my servlet is using the Java TimeZone class to get the current date/time. however, the timezone retrieved is incorrect (GMT+0) -- not the same as the operating system (Unix) timezone.
    But the time stamp in the Nas logs displays the correct timezone (for those entries generated by the server and not my application).
    any advice greatly appreciated.

    We also had a time zone problem with NAS on Unix. We found out that there was a name mismatchs with the time zones of Unix and Java. We solved the problem by forcing NAS to use a different time zone than Unix (or really the same, but with a different name) by modifing the kjs startup script (one of the last lines):
    $JAVA_HOME/bin/jre <i>-Duser.timezone=Europe/Paris</i> -mx128m -nojit com.kivasoft.engine.Engine $opts
    Regards / Per Huss

  • Can't get the little post sheet for twitter and facebook in the notification center

    I used to post from my notification bar but now they down open when i click on them, both facebook and twitter post.
    Tried logging out and changing the share widget button in setting>notification.
    Working on MBP 2012 OS X 10.8.4

    I am facing the similar issues on my OSX 10.8.4, I have tried to delete and add the FB and twitter account back, but no luck. I also went to activity monitor and quit the notification, still no go. Looks like a bug issue. Any one aware of the fix, pls help. I really do not want to reinstall the OS.

  • How can I get the number request's (count) for One interface

    Hi Guru's,
    I have a requirement,One interface say Hello world._How can I get the number request's (count) for this interface_.I thing with BAM it's possible.
    But I have no idea about BAM.If is there any alternative please give directions and instruction how to achieve this task.
    Can any body help.Thanks in advance.
    Regards
    Mani

    You have to query the SOA_INFRA schema to get the answer.
    Build a select query in cube_instance table.
    Thanks,
    Vijay

  • HT3215 Does anyone know the best (or acceptable) outputs (v and mA) for AC-USB chargers?  I have a few post-market choices, and I can't get the specs for the bona fide Apple $29 charger.

    Does anyone know the best (or acceptable) outputs (v and mA) for AC-USB chargers?  I have a few post-market choices, and I can't get the specs for the bona fide Apple $29 charger.  Thanks; no hurry.

    Does anyone know the best (or acceptable) outputs (v and mA) for AC-USB chargers?  I have a few post-market choices, and I can't get the specs for the bona fide Apple $29 charger.  Thanks; no hurry.

  • How can I get the context-parm from a web.xml file using struts?

    Hello:
    I need get the context-param from the web.xml file of my web project using struts. I want configurate the jdbc datasource connection pooling here. For example:
    <context-param>
    <param-name>datasource</param-name>
    <param-value>jdbc/formacion</param-value>
    <description>Jdbc datasource</description>
    </context-param>
    and then from any Action class get this parameter.
    Similar using a simple server can be:
    /** Initiates new XServlet */
    public void init(ServletConfig config) throws ServletException {
              for (Enumeration e = config.getInitParameterNames(); e.hasMoreElements();) {
                   System.out.println(e.nextElement());
              super.init(config);
              String str = config.getInitParameter("datasource");
              System.out.println(str);
         public void doPost(HttpServletRequest req, HttpServletResponse res)
              throws ServletException, IOException {
              // res.setContentType( );
              System.out.println("Got post request in XServlet");
              PrintWriter out = res.getWriter();
              out.println("nada");
              out.flush();
              out.close();
    but only this works for init-params, if I use
    <servlet>
         <servlet-name>MyServlet</servlet-name>
         <display-name>MyServlet</display-name>
         <servlet-class>myExamples.servlet.MyServlet</servlet-class>
         <init-param>
         <param-name>datasource</param-name>
         <param-value>jdbc/formacion</param-value>
    </init-param>
    </servlet>
    inside my web.xml. I need something similar, but using struts inside the action class for that I can get the context-params and call my database.
    Thank you

    To get context parameters from your web.xml file you can simply get the ActionServlet object from an implementing action object class. In the perform (or execute) method make the following call.
    ServletContext context = getServlet().getServletContext();
    String tempContextVar =
    context.getInitParameter("<your context param >");

  • Can not get the parameter?

    I use a form to upload files,
    like this:
    <form name="gdform10" action="upload.jsp" ENCTYPE="multipart/form-data" method="post">
    <input type="hidden" name="picName" value="wxds.jpg">
    <input type="file" name="file">
    <input type="submit" name="savePic" value="modify">
    </form>
    but I can not get the parameter picName in the upload.jsp,
    like :
    String pname = request.getParameter("picName");
    but pname is null.

    Hello,
    In Jsp, if you want to upload file, you can't directly use "request.getParameter()".
    There're two company provide components for you and it's free.
    First is jspsmart company, it offer jspsmartUpload component and link is
    http://www.jspsmart.com
    Second is o'reilly, it offer MultipartRequest component and links is http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html
    for example, you use oreilly component.
    <%@ page import="com.oreilly.servlet.MultipartRequest" %>
    String saveDirectory = "c:\\Upload\\";
    int maxPostSize = 5 * 1024*1024;
    MultipartRequest multi= new MultipartRequest(request,saveDirectory,maxPostSize );
    Enumeration filesname = multi.getFileNames();
    while(filesname.hasMoreElements()){
    String name = (String)filesname.nextElement();
    FileName = multi.getFilesystemName(name);
    File f = multi.getFile(name);
    String ContentType = multi.getContentType(name);
    ps. above codes is from book named "java server pages tech reference"

  • I am using 3.6. How can I get the update to look just like this version? I truly don't want to use IE or MSN but if that is all I have, then let me know. Thanks

    I am using 3.6 because I like how it spreads out my toolbars instead of just giving me the bookmarks in the corner and the lonesome firefox in the opposite corner. I know I can open the bookmark toolbar but it is not the same. I want the file, edit, view, history, bookmarks, tools, help toolbar across. How can I get the new firefox to do that

    This should duplicate the image that you posted as your preferred appearance for Firefox 5 in the above (request to be LOCKED) duplicate thread.
    '''Menu Bar'''<br />
    *right-click empty space at the end of the Tab Bar, click "Menu Bar" to place a checkmark
    *Menu Bar checked = Menu Bar on; Firefox button off
    *Menu Bar un-checked = Menu Bar off; Firefox button on
    *Other methods of doing the same:
    **click Firefox button > Options, click Menu Bar
    **Quick toggle Menu Bar on/off: ALT+V+T+M
    '''Tabs on Top'''<br />
    *right-click empty space at the end of the Tab Bar, click "Tabs on Top" to remove the checkmark
    *Tabs on Top checked = Tabs above toolbars
    *Tabs on Top un-checked = Tabs below toolbars
    *Other methods of doing the same:
    **click Firefox button > Options, click Tabs on Top
    **Quick toggle Tabs on Top on/off: ALT+V+T+T
    '''Separate Reload / Stop buttons and position of Home button'''<br />
    *Open the Customize window; do one of the following:
    **right-click the empty space at the end of the Tab bar, choose "Customize"
    **click Firefox button > Options > Toolbar Layout
    **if using the Menu Bar, click View > Toobars, click Customize
    **Quick open Customize window: ATL+V+T+C
    *the Reload and Stop buttons will be shown separate between the URL/Location bar and the Search Bar. While the Customize window is open, do one of the following, to keep the buttons separate:
    **drag the Stop button to the left of the Reload button
    **drag a "Space" between the Reload and Stop buttons
    **drag one or both buttons anywhere on the Navigation bar separated by a "Space" or another icon or reverse the order to Stop-Reload to keep them separate
    *drag the Home button to the right of the Search Bar
    *click "Done" at the bottom right of the Customize window when finished.
    '''Color Back/Forward, Home, Stop and Reload buttons'''<br />
    *Install this add-on: https://addons.mozilla.org/en-US/firefox/addon/firefox-3-theme-for-firefox/
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    Not related to your question, but...
    You need to update some plug-ins:
    *Plug-in check: https://www-trunk.stage.mozilla.com/en-US/plugincheck/
    *Adobe PDF Plug-In For Firefox and Netscape: [https://support.mozilla.com/en-US/kb/Using%20the%20Adobe%20Reader%20plugin%20with%20Firefox#w_installing-and-updating-adobe-reader Installing/Updating Adobe Reader in Firefox]

  • How can we get the value of the key field in a custom data model using governance API?

    Dear Team,
    How can we get the value of the key field in a custom data model, to be used for manipulation of the change request fields using governance API?
    Any kind of help would be sincerely appreciated.
    Thanks & Regards,
    Tushar.

    Hi Michael,
    Thanks for direction. Let me give more context on this as I'm interested to get more details..One of the issue was to read cross entity field values on UI based on user action and set other entity field behaviour...It is similar to what is being posted here.
    For ex: Reading MTART from Basic Data UIBB in MM MDG UI and set the field properties in some other custom entities say ZZETEST. This cannot be done using UI BADI as it only supports single entity at a time and not cross entity. So alternatively we found a solution where we can enhance existing PLMB feederclass cl_mdg_bs_mat_feeder_form by reading the model and the entity as needed as it it proved that it supports cross entity UI field behaviours and so business requirements.
    This is a workaround for now.
    So the question is How do we achive it using governance API for cross entity field behiaviours.?or what is the right way doing this.
    Can we do that using governance API and its' methods?
    In the Governance API doc you provided below has referring to below external model as part of gevernance API.
    The active or inactive data (before or during the derivation or the check) can be read
    with the external data model interface IF_USMD_MODEL_EXT with the method READ_CHAR_VALUE and
    the corresponding READ_MODE parameter. To avoid unnecessary flushes (derivations), the NO_FLUSH
    parameter should b
    e set to ‘X’.
    Thanks
    Praveen

  • How can I get the current user an  resource context  in a portal JSPDynPag

    How can I get the current user (com.sapportals.portal.security.usermanagement.IUser?)an the resource context  in a portal component (JSPDynPage)?
    Thanks.

    Hi Jon,
    Here is the code to get the current user and resource context in your JSPDynPage:
    IPortalComponentRequest  currentRequest  = (IPortalComponentRequest)pageContext.getAttribute(javax.servlet.jsp.PageContext.REQUEST);
    com.sapportals.portal.security.usermanagement.IUser contextUser = (com.sapportals.portal.security.usermanagement.IUser) currentRequest.getUser().getUser();
    ResourceContext resourceContext = new ResourceContext(contextUser);
    Greetings,
    Praveen Gudapati
    p.s. points are always welcome for helpful answers

  • How can I get the UserName in JAX-RPC?

    The client is just as following:
    import javax.xml.rpc.Call;
    import javax.xml.rpc.Service;
    import javax.xml.rpc.JAXRPCException;
    import javax.xml.rpc.namespace.QName;
    import javax.xml.rpc.ServiceFactory;
    import javax.xml.rpc.ParameterMode;
    public class ACTRPCClient {
    private static String qnameService = "Hello";
    private static String qnamePort = "Greeting";
    private static String BODY_NAMESPACE_VALUE ="http://hello.org/wsdl";
    private static String ENCODING_STYLE_PROPERTY ="javax.xml.rpc.encodingstyle.namespace.uri";
    private static String NS_XSD ="http://www.w3.org/2001/XMLSchema";
    private static String URI_ENCODING ="http://schemas.xmlsoap.org/soap/encoding/";
    public ACTRPCClient() {
    public static void main(String[] args) {
    try {
    String endpoint= "http://127.0.0.1:8080/SOAPListener/Hello";
    ServiceFactory factory =ServiceFactory.newInstance();
    Service service =factory.createService(new QName(qnameService));
    QName port = new QName(qnamePort);
    Call call = service.createCall();
    call.setPortTypeName(port);
    call.setTargetEndpointAddress(endpoint);
    call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
    call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
    call.setProperty(ENCODING_STYLE_PROPERTY,URI_ENCODING);
    //here I set the username and password
    call.setProperty("javax.xml.rpc.security.auth.username","tomcat");
    call.setProperty("javax.xml.rpc.security.auth.password","tomcat");
    QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
    call.setReturnType(QNAME_TYPE_STRING);
    call.setOperationName(new QName (BODY_NAMESPACE_VALUE, "getHello"));
    call.addParameter("Greeting", QNAME_TYPE_STRING, ParameterMode.PARAM_MODE_IN);
    String[] params = { new String("Hello!") };
    String result = (String)call.invoke(params);
    System.out.println(result);
    } catch (Exception ex) {
    ex.printStackTrace();
    On the server side,I wrote a my own servlet to receive the soap instead of the jax-rpc.But I can't get the username from the request.
    for example,
    String username;
    username=request.getRemoteUser();
    I noticed that in the api doc,it says when the user has not been authenticated the method getRemoteUser will return null.So I use the username "tomcat" ,password "tomcat "in the tomcat-
    users.xml.But I still can't get the username,why?
    Thanks for your help.

    From the Axis I find the problem,the username and password is stored in the headers of the http.
    And now the jax-rpc only surpport basic authentication,we can get them by calling request.header("Authentication").Howerver,the infomation is encoded by Base64.We copy a module from the Axis to decode the infomation.That's it,but still thank your attention.

  • Where can I get the codec to import iMovie clips into Premiere CS6?

    I am running a PC with Win7 & PPro CS6
    I have a bunch of clips that were copied over from iMovie imports (no original files exist anymore)
    They are all a special form of .mov
    I can play them in VLC Media Player (but not Quicktime, or WMP) so I know that a pc can handle them...
    When I import into CS6 I get an errorsaying Codec missing or unavailable...
    Whered can I get the proper Codec?
    Thanks all!
    Aza

    Considering the last post was made in March last year, I've attached the feature request I made today, just so you know you're not alone on this issue, for anyone with the same problem.
    MAC to PC Support:
    There needs to be a comprehensive and readily supplied library of codecs to provide simple transitions between MAC and PC.
    I'm currently working on my first feature film. I raised a little bit of money through Kickstarter, enough to buy a decent HD camera and a microphone. Basically, I'm not a professional and I'm learning as I go. The camera I bought is a Canon XHA1- it records to mini-DV. I do not have the money to buy an HDV tape deck, leaving me with the only other option of using the firewire port to capture footage off of the camera itself. I had a firewire-to-USB cable, which I used to capture footage to my PC, but after getting a new computer with Windows 8, the camera is now out of date and the OS has no drivers for it. I then decided to capture my footage on an old i-Mac my friend gave me, through i-Movie. After moving the files to my PC, I found that Premiere Pro CC was unable to import them.
    Needless to say, the song and dance I have to go through every time I try to capture footage is frustrating, and considering the mission of Adobe Creative Cloud, to provide affordable opportunities and resources to independent artists, not to mention the fact that Adobe is for both Mac and PC (and especially not mentioning the fact that it is a service I am paying for monthly,) I feel like these kinds of problems shouldn't exist.
    Of course saying "I pay for this, this problem shouldn't exist" is the rallying cry for every idiot who expects the impossible. But capturing on i-Movie... and importing to Premiere Pro? Really? Why is this an issue? Maybe i-Movie is out of date... but I'm not going to waste another weekend capturing; it probably still won't work.
    I'm not asking for file conversion software. That's what I'm going to have to do on my own, for GBs upon GBs of footage just so I can get to the editing table. The problem is that I have to convert it in the first place. If there is any progress on this issue, please let me know.

  • An App I downloaded for my iPad was not what I thought it was going to be, can I remover the App and request a refund?

    An App I downloaded for my iPad was not what I thought it was going to be, can I remover the App and request a refund?

    You probably cannot get a refund, since as RG said the terms of sale for the iTunes Store state that all sales are final. You can contact the iTunes Store, explain the reason for your request, and ask, though:
    http://www.apple.com/support/itunes/contact.html
    It's possible they'll make an exception for you, something more likely if the app does not perform as advertised.
    Good luck.
    Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Communities page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums and in the Apple Knowledge Base, before you post a question.

  • Getting the last posting date

    Hi everybody,
    I need some help. I want to create a Bex Variable with Customer Exit, and i need to modify the ABAP code in order to get the last posting date of Data in my request. I'll like to create to create with BEx Query Designer a request that allows me to make my report on the most recent data only.
    Eg. Let's say today before leaving the work I launch a routine that provides me during the night data for my R/3 system and I'm wonking in a BW environment. Tomorrow, i'll like to compose any request guiving me informations only on what i loaded yesterday without typing the date. I'm oblige to use a variable, but I need the corresponding Abap code. Can some one help me please ?
    Thanks.

    You want your query to return results from only the most recently loaded request. Is that right? You don't need a variable for that. Just bring in "Request ID" (from Data Package dimension) into Filter area and use "Last Request Loaded" variable delivered by SAP.

  • Can we get the porlet name of which the JSP file is resided ?

    Hi all,
    Can we get the portlet name of which the JSP file is resided?
    Sincerely,
    Alan.

    you could try the following code
    <%@ page import="com.bea.portal.model.Portlet"%>
    <%@ page import="com.bea.portal.model.PortletState"%>
    <%@ page import="com.bea.portal.render.servlets.jsp.PortletRenderHelper"%>
    PortletState portletState = PortletRenderHelper.getPortletState( request);
    String portletName = portletState.getDisplayName();
    "Alan Liu" <[email protected]> wrote:
    Hi all,
    Can we get the portlet name of which the JSP file is resided?
    Sincerely,
    Alan.

Maybe you are looking for