7
回答
可正常编译,运行却提示找不到该类。
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

我创建了一个servlet类,里面有一处代码使用到了com.sun.deploy.util.ArrayUtil,可以编译通过,但通过Tomcat运行触发却提示找不到这个类(异常处已经标记红色),想请教下大家可能是什么原因造成的?

异常截图:

类:

package cn.com.liuxuan.servlet;
import com.sun.deploy.util.ArrayUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by daxuan on 2017/8/30.
 */
public class FormServlet extends HttpServlet {


//    getParameter 用于获取单个参数
    private String demoGetParameter(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//     由于浏览器URL中默认采用IOS8859-1编码,所以需要将URL中中文进行转码。
        String name = new String(req.getParameter("name").getBytes("ISO8859-1"),"UTF-8");
        String age =  req.getParameter("age");
        return "name:"+name+"<br/>age:"+age;
    }

    // getParameterValues 用户获取参数中含有多个值
    private String demoGetParameterValues(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String [] interests = req.getParameterValues("interests");

        return "interest:"+ ArrayUtil.arrayToString(interests);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应内容类型
        resp.setContentType("text/html;charset=UTF-8");

//        String message = demoGetParameter(req,resp);
        String message = demoGetParameterValues(req,resp);
        PrintWriter out = resp.getWriter();
        out.print(message);
        System.out.println("in doGet...");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
        System.out.println("in doPost...");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("FormServlet 被执行...");
    }
}

IDEA配置:

<无标签>
举报
大轩
发帖于3个月前 7回/123阅
顶部