cPanel godaddy.com中找不到servlet错误

时间:2017-09-23 18:37:09

标签: java web-services servlets web web-hosting

我在 godaddy.com 上已经注册了域名,例如www.example.com(例如)并拥有cPanel帐户。我已经部署了我的项目的.war文件并将其上传到cPanel然后将其解压缩。当我访问我的域(www.example.com)时,初始的index.jsp文件正在加载,并且所有的javascript文件都能正常工作。但是当它必须从javascript文件引发AJAX请求时,它会说'404错误。没找到Servlet!'那么我的servlet和类文件在 Public_html / WEB-INF / classes / com / Fb / FaceBookServlet.java 文件夹下,这里是我的web.xml文件

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>FaceBookServlet</servlet-name>
<servlet-class>com.Fb.FaceBookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FaceBookServlet</servlet-name>
<url-pattern>/FaceBookServlet</url-pattern>
</servlet-mapping>

重要的是“它在eclipse中运行良好,在涉及到网络时却不行” ....请帮我解决这个问题

enter image description here

这是结构 这是我的 index.jsp

<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">

</head>
<body>
<script type="text/javascript" src="Js/FaceBookSDK.js"></script>
<script 
src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js">
</script>
<script type="text/javascript" src="Js/Fb.js"></script>
<script>
$(document).ready(function(){
    $('#loginBtn').click(function() {
        FacebookApp.signInPage();
    });
    $('#logoutBtn').click(function() {
        FacebookApp.signOutPage();
    });
    $('#postFeed').click(function() {
        FacebookApp.postFeedOnWall();
    });
    $('#postPhoto').click(function() {
        FacebookApp.findGameOfThronesCharacter();
    });
});
</script>

<input type="button" value="Sign in to Facebook" id="loginBtn"><br><br>
<input type="button" value="Sign out" id="logoutBtn"><br><br>
<input type="button" value="Post your message" id="postFeed"><br><br>
<input type="button" value="Post your photo" id="postPhoto"><br><br>
<img id="img"></img>

</body>

FaceBookServlet.java:

package com.Fb;

import java.awt.Graphics;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;

public final class FaceBookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public FaceBookServlet() {
    super();

}

protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {

}


protected void doPost(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
    try {
        JSONObject obj = new JSONObject();
        String picture_source = request.getParameter("picture_source");
        String local_picture_directory = 
request.getParameter("local_picture_directory");
        Random random = new Random();
        int randomNumber = random.nextInt(5)+1;
        BufferedImage image1 = ImageIO.read(new URL(picture_source));
        BufferedImage image2 = ImageIO.read(new 
URL(local_picture_directory+randomNumber+".png"));
        image1 = resizeImage(image1,200,200);
        image2 = resizeImage(image2,200,200);
        int w = 2*image1.getWidth();
        int h = image1.getHeight();
        BufferedImage combined = new BufferedImage(w, h, 
BufferedImage.TYPE_INT_ARGB);
        Graphics g = combined.createGraphics();
        g.drawImage(image1, 0, 0, null);
        g.drawImage(image2, image1.getWidth(), 0, null);
        g.dispose();
        ImageIO.write(combined, "PNG", new File("Image.png"));
        obj.put("filename", "Image.png");
        response.setContentType("application/json");
        response.getWriter().print(obj);
    }
    catch(Exception e) {

    }
}
public BufferedImage resizeImage(BufferedImage image,int width,int 
height) {
    BufferedImage newImage = new 
BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
    Graphics g = newImage.getGraphics();
    g.drawImage(image, 0, 0, width, height, null);
    g.dispose();
    return newImage;
}

}

Fb.js:

var FacebookApp = {
    isConnected : null,
    signInDetails: null,
    IMAGEFILE_DIRECTORY: "http://www.sellu.online/Images/",
    signInPage: function() {
        FB.getLoginStatus(function(response) {
            if(response.status==='connected') {
                FacebookApp.isConnected = 1;                    
                FB.api('/me',
{fields:'name,id,birthday,locale,first_name,last_name,picture,gender'}, 
function(resp) {
                if(resp) {
                    FacebookApp.signInDetails = resp;
                }   
                });
                alert("Signed in Successfully!!")
            } else {
                FB.login(FacebookApp.getUserData, {scope: 
'email,public_profile,user_birthday,publish_actions', return_scopes: 
true});
            }
            });
    },
     getUserData: function(response) {
        if(response.authResponse) {
            FacebookApp.signInPage();
        } else {
            alert("Sorry!!! Can't get into facebook");
        }
    },
    signOutPage: function() {
        if(FacebookApp.isConnected === null) {
            FB.getLoginStatus(function(response){
                if(response.status === 'connected') {
                    FacebookApp.isConnected = 1;
                } else {
                    FacebookApp.isConnected = 0;
                }
                FacebookApp.signOutResult();
            });
        } else {
            FacebookApp.signOutResult();
        }
    },
    signOutResult: function() {
        if(FacebookApp.isConnected === 1) {
            FB.logout(function(response) {
                if(response) {
                    FacebookApp.isConnected = 0;
                    alert("Logged out successfully");
                } else {
                    alert("Can't logged out!!");
                }
            });
        } else if(FacebookApp.isConnected === 0) {
            alert("You've not logged in before!!");
        }
    },
    postFeedOnWall: function(content,picSrc,webLink) {
        FB.api('/me/feed', 'post', { message: 
content,source:picSrc,link:webLink }, function(response) {
              if (!response || response.error) {
                  console.log(response.error);
                alert('Error occured in posting feed');
              } else {
                alert('Post ID: ' + response.id);
              }
            });
    },
    postPhotoOnWall: function(picSrc,picCaption) {
        FB.api('/me/photos', 'post', { url: picSrc,caption: 
picCaption}, function(response) {
              if (!response || response.error) {
                  console.log(response.error);
                alert('Error occured in posting picture');
              } else {
                alert('Post ID: ' + response.id);
              }
            });
    },
    findGameOfThronesCharacter: function() {
        var params={};
        params.picture_source = FacebookApp.getProfilePicture(500);
        params.local_picture_directory = null;
        if(FacebookApp.signInDetails && 
FacebookApp.signInDetails.gender) {
            if(FacebookApp.signInDetails.gender === 'male') {
                params.local_picture_directory = 
FacebookApp.IMAGEFILE_DIRECTORY + 'GOT/MEN/';
            } else {
                params.local_picture_directory = 
FacebookApp.IMAGEFILE_DIRECTORY + 'GOT/WOMEN/';
            }
        }
        $.post('FaceBookServlet',params,function(result) {
            if(result.filename) {
                $('#img').removeAttr('src');

$('#img').attr('src',FacebookApp.IMAGEFILE_DIRECTORY+result.filename);
                FacebookApp.postFeedOnWall("Find your game of thrones 
character!!",
FacebookApp.IMAGEFILE_DIRECTORY+result.filename,"www.sellu.online");
            }
        }); 
    },
    getProfilePicture: function(width) {
        var src = null;
        if(FacebookApp.signInDetails) {
            src = 
'https://graph.facebook.com/'+FacebookApp.signInDetails.id+"/picture?
type=large";
            if(width) {
                src += '&width='+width;
            }
        }
        return src;
    }

}

FaceBookSDK.js:

window.fbAsyncInit = function() {
      FB.init({
        appId      : 'xxxxxxxxxxxxxxxxx',
        cookie     : true,  
        xfbml      : true,  
        version    : 'v2.8' 
      });
};
      (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));

0 个答案:

没有答案