java 在jsp页面中创建一个对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15950166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:24:15  来源:igfitidea点击:

creating an object within a jsp page

javajspservletssyntax

提问by kholofelo Maloma

I am developing a web app. I have a disptacher servlet which successfully calls a JSP page, but this JSP has to read data from some other object... but it would find it...

我正在开发一个网络应用程序。我有一个成功调用 JSP 页面的调度程序 servlet,但是这个 JSP 必须从其他对象读取数据......但它会找到它......

this is the line which wont locate "BackendServer" class. It gives me a ClassNotFoundException error...

这是不会定位“BackendServer”类的行。它给了我一个 ClassNotFoundException 错误......

  <%=new BackendServer().run("getCar")%>

basically the above line of code is within the JSP... if I remove it, the app runs well without the output of this line

基本上上面的代码行在 JSP 中......如果我删除它,应用程序运行良好,没有这一行的输出

I have imported BackendServer on top this way:

我以这种方式在顶部导入了 BackendServer:

  <%@page import="com.servlet.java.*"%>

how can I make my JSP find my BackendServer?

如何让我的 JSP 找到我的 BackendServer?

thanks in advance :)

提前致谢 :)

回答by Shreyos Adikari

Try adding a space like:

尝试添加一个空格,如:

<%@ page import="com.servlet.java.*"%>

And make sure if the file comes from a jar, put the jar into the lib.

并确保文件来自 jar,将 jar 放入 lib。

回答by CloudyMarble

Why do not you use Beans:

为什么不使用 Beans:

<jsp:useBean id="VarName" class="BackendServer"  scope = *page | request | session |application*/>

回答by tgkprog

write the fully qualified name. com.servlet.java.BackendServer is your class?

写出完全限定的名称。com.servlet.java.BackendServer 是你的类吗?

are you sure the jar of this class is in classpath of this web app?

你确定这个类的 jar 在这个 Web 应用程序的类路径中吗?

where is the jar?

罐子在哪里?

where is the app.

应用程序在哪里。

should be in common lib, global app container classpath or this web apps path

应该在公共库、全局应用程序容器类路径或此 Web 应用程序路径中