小编San*_*one的帖子

Rails通过ajax闪烁通知

长话短说,我有一个按钮.点击它,我想要一个ajax请求被触发,它获取flash [:notice]并将其显示在$中的div中

这是我的简短观点:

 <input type="button" id="search" value="display"/>

 <div id="notice">

 </div>
Run Code Online (Sandbox Code Playgroud)

我在视图中的ajax请求:

$("#search").submit(function(){
                            $.ajax({
                                type: "POST",
                                url: //url to my show action
                                success: function(data){
                                      /*$("#notice").html("<%= flash[:notice] %>");
                                        $("#content").html(data);*/
                                }
                            });
                            return false;
                    });
Run Code Online (Sandbox Code Playgroud)

我的控制器:

def HomeController <  ActionController::Base
  def index

  end

  def show
    respond_to do |format|
    format.js {  flash[:notice] = "" + count.to_s + " results found for " + params[:query][:search_key] + "" }
    end
    #render :partial => 'search'
  end
end
Run Code Online (Sandbox Code Playgroud)

我的show.js.erb

#app/views/dashboard_home/show.js.erb
$("#notice").html("<%=j flash[:notice] %>");

$("#content").html("<%=j render partial: "search" %>"); …
Run Code Online (Sandbox Code Playgroud)

javascript flash ajax jquery ruby-on-rails

26
推荐指数
2
解决办法
4万
查看次数

在JSP中使用IF条件

我有这条线

<td><c:out value="${row.file_name}"/></td>
Run Code Online (Sandbox Code Playgroud)

file_name是mysql数据库表中的列名.我想检查file_name是否有一些值,所以我想使用IF condition,但是如何通过row.file_name?就像是if(row.file_name!=null){}

UPDATE

<td><c:out value="${row.file_name}"/><br>
<c:choose>
    <c:when test="${row.file_name == null}">
         Null
    </c:when>
    <c:otherwise>
       <a href="downloadFileServlet?id=${row.id}">Download</a></td>
    </c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,即使file_name为空,也只执行第二个条件

java jsp if-statement jstl

9
推荐指数
1
解决办法
4万
查看次数

document没有包含itext的页面

<%
OutputStream output=response.getOutputStream();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "inline; filename=details.pdf");
try{
    Document document = new Document();
PdfWriter writer=PdfWriter.getInstance(document, output);
document.open();
XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/a", "root", "root");
Statement st=con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
List arrlist = new ArrayList();
ResultSet rs=st.executeQuery("Select * from user_start1");
 while(rs.next()){
 arrlist.add(rs.getString("data"));
 }  
for(int i=0;i<12;i++){
  String str =(String) arrlist.get(i);
  System.out.println(str); 
  worker.parseXHtml(writer, document, new StringReader("helloworld"));
}
document.close();
writer.flush();
writer.close();
output.close();
}catch(IOException e){e.printStackTrace();} 
%>
Run Code Online (Sandbox Code Playgroud)

抛出错误

SEVERE: Servlet.service() for servlet [jsp] in context with path [/chieflegis] threw exception [ExceptionConverter: java.io.IOException: The document …
Run Code Online (Sandbox Code Playgroud)

java itext

6
推荐指数
2
解决办法
3万
查看次数

在所有页面上使用虾的背景图像

我在视图中有这个代码

prawn_document(:page_size=> "A4", :top_margin => 80, :bottom_margin => 40,
               :background => "public/uploads/1.png") do |pdf|

  creation_date = Time.now.strftime('%d-%m-%Y')
  posts = @posts.each do |post|
    pdf.pad(10) do
      pdf.text post.title
      pdf.text post.text
    end
  end

  pdf.page_count.times do |i|
    pdf.go_to_page(i + 1)
    pdf.draw_text "Creation Date : " + creation_date, :at => [200, 780]
    pdf.draw_text "Page : #{i + 1} / #{pdf.page_count}", :at => [450, -3]
  end
end
Run Code Online (Sandbox Code Playgroud)

这给了我以下输出:

在此输入图像描述

还有这个

在此输入图像描述

正如您在第一张图像中看到的那样,图像不居中.

在第二张图像上,您可以看到图像不适合整页.

我还尝试将图像添加到每个页面,这是我添加页码的方式,但这里图像与文本重叠.但在这里,我可以按照我想要的方式定位图像,但只是它与文本重叠.

如果我放入标题,我无法定位和调整图像大小.

所以我需要帮助使图像适合页面.图像为700px x 700px.

我也试过使用PDFkit,但是无法获得页码,我觉得我几乎都在使用Prawn,但只是这个图像.即使是不同的解决方案也会受到青睐.

ruby pdf ruby-on-rails prawn

6
推荐指数
1
解决办法
1880
查看次数

在wickedpdf上使用javascript的页码

这是我的控制器

class WelcomeController < ApplicationController
  def index
    respond_to do |format|
      format.html
      format.pdf do
        render :pdf => "my_pdf", # pdf will download as my_pdf.pdf
        :layout => 'pdf', # uses views/layouts/pdf.haml
        :margin => { :top => 30 },
        :header => {template: 'layouts/pdf_header.html'},
        :show_as_html => params[:debug].present? # renders html version if you set debug=true in URL
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我的视图很完美,但标题中没有任何页码对于页码我使用了这段代码

pdf_header.html.erb

<html>
  <head>
    <script>
      function number_pages() {
        var vars={};
        var x=document.location.search.substring(1).split('&');
        for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
        var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
        for(var …
Run Code Online (Sandbox Code Playgroud)

javascript ruby-on-rails wkhtmltopdf wicked-pdf

1
推荐指数
1
解决办法
2964
查看次数

Separating an array into Strings

ArrayList<String> stock_list = new ArrayList<String>();
stock_list.add("stock1");
stock_list.add("stock2");
Run Code Online (Sandbox Code Playgroud)

I have this ArrayList, how do I separate into separate Strings so that I get String a="stock1"; String b="stock2"?

java

0
推荐指数
1
解决办法
69
查看次数