- 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());
}
}
}