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,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题