Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7041615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:04:03+00:00 2026-05-28T02:04:03+00:00

i’m new in a web service. i’m trying to make a simple web service

  • 0

i’m new in a web service. i’m trying to make a simple web service REST on java for a simple login application.. here’s my code:

Server side:

package com.testingws.webservices;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


@Path("/login/{username}/{password}/{datetime}")
public class webServicesClass {
    @GET   // this method process GET request from client
    @Produces("application/json")   // sends JSON
    public String getJson( @PathParam("username") String username, @PathParam("password") String password) {  // empno represents the empno sent from client   
        if (username.equalsIgnoreCase("admin") && password.equalsIgnoreCase("admin")){
            return "{'loginstatus':'success'}";
        }
        else{
            return "{'loginstatus':'failed'}";
        }
    } // end of

}

Client side :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Client Login</title>
<script type="text/javascript">
    function loginProcess(){
        var tempUser = document.getElementById("loginUsername");
        var tempPass = document.getElementById("loginPassword");

        var dateTime = new Date();
        var url = "http://localhost:8181/TestWSProject/authentication/login/" + tempUser.value + "/" + tempPass.value + "/" + dateTime.toUTCString();

        var xmlhttp = new XMLHttpRequest(); //@slaks: i put it here

        xmlhttp.open('GET',url,true);
        xmlhttp.send(null);
        xmlhttp.onreadystatechange = function() {
               if (xmlhttp.readyState == 4) {
                  if ( xmlhttp.status == 200) {
                       var det = eval( "(" +  xmlhttp.responseText + ")");

                       //alert(det.loginstatus);
                       if(det.loginstatus=="success")
                       {
                           setCookie("login", "yes", 1);
                           window.location="main.html";
                       }
                       else
                       {
                           alert("incorrect username or password");
                       }

                 }
                 else
                       alert("Error ->" + xmlhttp.status + xmlhttp.responseText);
              }
        }
    }

    function getCookie(c_name)
    {
      var i,x,y,ARRcookies=document.cookie.split(";");
      for (i=0;i<ARRcookies.length;i++)
      {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name)
        {
          return unescape(y);
        }
      }
    }

    function setCookie(c_name,value,exdays)
    {
      var exdate=new Date();
      exdate.setDate(exdate.getDate() + exdays);
      var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
      document.cookie=c_name + "=" + c_value;
    }

    function checkCookie()
    {
        var loginStatus=getCookie("login");
        //alert(loginStatus);
        if (loginStatus=="yes")
        {
            //alert("Masuk pengecekan") 
            window.location="main.html";
        }
    }
</script>
</head>
<body onload="checkCookie()">
    <h2>LOGIN FORM</h2>
    <BR>
    Username : <input type="text" id="loginUsername"/>
    <BR>
    Password : <input type="password" id="loginPassword"/>
    <BR>
    <input type="button" value="Login" onclick="loginProcess()"/>
</body>
</html>

when i access my client from webContent url (http://localhost/TestWSProject/index.html) that service works perfectly, but if i access my client from stand alone HTML file (file:///D:/+Prog/webservice/TestWSProject/WebContent/index.html) it give me xmlHTTPStatus = 0 and that service is not works.. any solution for this problem?? really thanks..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:04:03+00:00Added an answer on May 28, 2026 at 2:04 am

    Some browsers have security restrictions which restrict files from performing certain actions if they are being accessed directly from the file system.

    This could be what is causing the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.