yxwisdom 2016-05-23 12:19 采纳率: 0%
浏览 1355
已结题

jsp调用javabean问题! 求大神解答啊!!

  1. jsp中调用javabean,报错如下: org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 13 in the jsp file: /send.jsp
The type org.apache.http.client.ClientProtocolException cannot be resolved. It is indirectly referenced from required .class files
10: String mywords = request.getParameter("message");
11: String t = "";
12: box.setMsg(mywords);
13: String Text=box.func();
14: if (application.getAttribute("words") == null
15: && mywords != null) {
16: t = "鎴戯細" + ":" + mywords + "
" + "鏈哄櫒浜猴細"

An error occurred at line: 13 in the jsp file: /send.jsp
The method func() from the type Box refers to the missing type ClientProtocolException
10: String mywords = request.getParameter("message");
11: String t = "";
12: box.setMsg(mywords);
13: String Text=box.func();
14: if (application.getAttribute("words") == null
15: && mywords != null) {
16: t = "鎴戯細" + ":" + mywords + "
" + "鏈哄櫒浜猴細"

请问是怎么回事啊

jsp文件:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" contentType="text/html;charset=GB2312"%>



/jsp:useBean
<%
try {
request.setCharacterEncoding("GB2312");
String mywords = request.getParameter("message");
String t = "";
box.setMsg(mywords);
String Text=box.func();
if (application.getAttribute("words") == null
&& mywords != null) {
t = "我:" + ":" + mywords + "
" + "机器人:"
+ Text + "
";
application.setAttribute("words", (Object) t);
} else if (mywords != null) {
t = (String) application.getAttribute("words");
t += "我:" + ":" + mywords + "
" + "机器人:"
+ Text + "
";
application.setAttribute("words", (Object) t);
}
} catch (Exception e) {
}
%>

type="submit" value="send">


javabean文件:
package bean;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Scanner;

import net.sf.json.JSONObject;

import org.apache.http.client.ClientProtocolException;

public class Box {
String msg;
public Box()
{
msg=null;
}
public String getMsg() {
return msg;
}

public void setMsg(String msg) {
    this.msg = msg;
}
public String func1()
{
    return "OK";
}
public String func() throws ClientProtocolException, IOException
{

    String APIKEY="**********************";
    String INFO = URLEncoder.encode(msg, "utf-8");  
    String requesturl = "http://www.tuling123.com/openapi/api?key="+APIKEY+"&info="+INFO+"&userid=wisdom123";  
    URL getURL=new URL(requesturl);
    HttpURLConnection connection=(HttpURLConnection)getURL.openConnection();
    connection.connect();

    BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getInputStream(), "utf-8"));
    StringBuffer sb = new StringBuffer();
    String line = "";
    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }
    reader.close();
    connection.disconnect();
    String a=sb.toString();
    JSONObject obj= JSONObject.fromObject(a);
    //System.out.println();

    return obj.getString("text");
}
public static void main(String[] args) throws ClientProtocolException, IOException {

    String msg=null;
    while(true)
    {
        Scanner input=new Scanner(System.in);
        //System.out.println("请输入聊天内容:");
        msg=input.nextLine();
        Box a=new Box();
        a.setMsg(msg);
        System.out.println(a.func());
    }

}

}

  • 写回答

5条回答 默认 最新

  • Robot-C 2016-05-23 12:22
    关注

    1.在使用时对于需要填写属性的表单名称应该与JavaBean中的属性名称一样
    2.JavaBean类中必须含有无参构造器......
    答案就在这里:JSP中的JavaBean问题
    ----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

    评论

报告相同问题?

悬赏问题

  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)