鍍金池/ 問(wèn)答/Java  Linux/ HttpServlet使用Gson報(bào)錯(cuò):java.lang.ClassNotFo

HttpServlet使用Gson報(bào)錯(cuò):java.lang.ClassNotFoundException

開(kāi)發(fā)工具:Intellij idea
用maven的方式導(dǎo)入 Gson開(kāi)源庫(kù):

clipboard.png

clipboard.png

代碼正常編譯,運(yùn)行時(shí)報(bào)錯(cuò)。

import bean.DeptInfo;
import com.google.gson.Gson;
import com.oracle.tools.packager.Log;

import java.io.IOException;
import java.util.logging.Logger;

@javax.servlet.annotation.WebServlet(name = "HelloHttp")
public class HelloHttp extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

        String method = request.getMethod();
        String url = request.getRequestURL().toString();

        System.out.println("method = " + method + "   url  = "  + url);

        DeptInfo info = new DeptInfo();
        info.deptId = 255;
        info.name = "第二項(xiàng)目部";
        try {
            String json = new Gson().toJson(info);
            if(json!=null){
                System.out.println("json = " + json);
            }
        }catch (Exception e){
            System.out.println("excp = " + e.getMessage());
        }

        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().println("121212");
        response.getWriter().close();
    }
}

clipboard.png

回答
編輯回答
厭遇

clipboard.png

2017年1月7日 03:02
編輯回答
愛(ài)是癌

jar包可能沒(méi)有自動(dòng)部署到web server下面吧,檢查一下看看有沒(méi)有

2018年1月10日 11:56
編輯回答
風(fēng)畔

還是jar 包 沒(méi)有導(dǎo)入 環(huán)境里

2017年10月11日 10:19