Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在JSP上导入2个代理_Java_Jsp - Fatal编程技术网

Java 在JSP上导入2个代理

Java 在JSP上导入2个代理,java,jsp,Java,Jsp,我的代码有问题。我需要在JSP上导入两个代理。我不知道为什么,但每当导入我的其他代理包时,我的代码都会出错。我曾想过将导入代码放在if-else语句中,但它不起作用。我的代码有问题吗 <%@ page language="java" %> <%@ page import="java.lang.String"%> <% int i = 1; if (i == 0){ %> <%@ page import ="com.x.x.functi

我的代码有问题。我需要在JSP上导入两个代理。我不知道为什么,但每当导入我的其他代理包时,我的代码都会出错。我曾想过将导入代码放在if-else语句中,但它不起作用。我的代码有问题吗

<%@ page language="java" %>
<%@ page import="java.lang.String"%>

<%
int i = 1;

if (i == 0){
%>
        <%@ page import ="com.x.x.function" %>
        <%@ page import ="com.x.x.functionViDocument" %>
        <%@ page import ="com.x.x.types.*" %>
<%  
 }else {
%>
        <%@ page import ="com.x.x2.function" %>
        <%@ page import ="com.x.x2.functionViDocument" %>
        <%@ page import ="com.x.x2.types.*" %>
<%  
}
%>

您不能在Java中执行条件导入。JSP被转换为java类(扩展了HttpServlet),而您的代码不是有效的java代码

您可以在代码中使用完全限定的类名。如果需要
功能
,则:

com.x.x.Function fn1=…
com.x.x2.Function fn2=…

然而,这不是一个好的做法。最好您应该有一个
函数
类都实现的接口,这样您就不会有太多条件复制粘贴的代码

另外两件事:使用大写的类名(
Function
,而不是
Function
)。不要用JSP编写java代码。改用servlet