我需要将var keyboardHasShown = false
@objc func keyboardWillChange(notification: Notification){
guard let keyboardRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else {
return
}
if notification.name == UIResponder.keyboardWillShowNotification {
if keyboardHasShown == false {
view.frame.origin.y = -keyboardRect.height/3
}
keyboardHasShown = true
} else {
view.frame.origin.y = 0
keyboardHasShown = false
}
}
集成到动态Web应用程序中,并想在jasper
服务器中运行。.但是它抛出错误。
wildfly
我试图编译此Web动态项目并在Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:95)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:198)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:449)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:359)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:652)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.jsp.JspFileHandler.handleRequest(JspFileHandler.java:32)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
JBWEB004060: An error occurred at line: 19 in the jsp file: /reportPage.jsp
JasperExportManager cannot be resolved
16:
17: JasperReport jasperReport=JasperCompileManager.compileReport(input);
18: JasperPrint jasperPrint=JasperFillManager.fillReport(jasperReport,null);
19: JasperExportManager.exportReportToPdfStream(jasperPrint,response.getOutputStream());
20:
21: response.getOutputStream().flush();
22: response.getOutputStream().close();
中运行war文件,但是会引发错误。
答案 0 :(得分:0)
在从字体结尾请求的控制器上运行此代码,您的问题将得到解决。让我知道是否还有其他问题。
try {
InputStream jasperStream = null;
// when your jasper file is under classes/jasper repository
jasperStream = this.getClass().getResourceAsStream("/jasper/ReceiveReport.jasper");
JasperPrint print = JasperFillManager.fillReport(jasperStream, params, new com.xx.xx.DataSource(columnData, columnNames));
File pdf = File.createTempFile("Your Report File", ".pdf");
JasperExportManager.exportReportToPdfStream(print, new FileOutputStream(pdf));
FileInputStream fileInputStream = null;
byte[] bytes = new byte[(int) pdf.length()];
try {
fileInputStream = new FileInputStream(pdf);
fileInputStream.read(bytes);
fileInputStream.close();
} catch (Exception ignored) {
}
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename= Your Report File.PDF");
response.setContentLength(bytes.length);
response.getOutputStream().write(bytes);
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (JRException | IOException e) {
e.printStackTrace();
}
这是您需要包含的外部自定义DataSource类
import java.util.Iterator;
import java.util.List;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
public class DataSource implements JRDataSource {
private String[] fields;
private Iterator iterator;
private Object currentValue;
public DataSource(List list, String[] fields) {
this.fields = fields;
this.iterator = list.iterator();
}
public Object getFieldValue(JRField field) throws JRException {
Object value = null;
int index = getFieldIndex(field.getName());
if (index > -1) {
Object[] values = (Object[]) currentValue;
value = values[index];
}
return value;
}
public boolean next() throws JRException {
currentValue = iterator.hasNext() ? iterator.next() : null;
return (currentValue != null);
}
private int getFieldIndex(String field) {
int index = -1;
for (int i = 0; i < fields.length; i++) {
if (fields[i].equals(field)) {
index = i;
break;
}
}
return index;
}
}