jsp调用javabean问题! 求大神解答啊!! 1C
  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个回答

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

javabean中的文件在控制台是运行正常的,求大神解答

不能编译jsp文件,,估计是少了jar包吧,,

重启Tomcat、刷新就好了。好像是Tomcat 自身加载ClassFile 的问题

清空Tomact 下Work目录的内容

重启Tomcat、刷新就好了。好像是Tomcat 自身加载ClassFile 的问题

清空Tomact 下Work目录的内容

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问