javascript 像普通打印一样通过jsp打印页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9394248/
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-26 06:31:29  来源:igfitidea点击:

print page by jsp like normal printing

javascripthtmljspprinting

提问by Tom

Ok finally i need to ask my question here as i did not find any solution. My question is how can i print a jsp page when i click on print button(on that page)? For example i have a jsp page and i have written something then when i click on print button(like submit button) then that jsp page will be sent to print and when i will click print on that print screen then page will be printed. Any help please?

好的,最后我需要在这里问我的问题,因为我没有找到任何解决方案。我的问题是当我点击打印按钮(在那个页面上)时如何打印一个 jsp 页面?例如,我有一个 jsp 页面,我写了一些东西,然后当我单击打印按钮(如提交按钮)时,该 jsp 页面将被发送以进行打印,当我在该打印屏幕上单击打印时,页面将被打印。请问有什么帮助吗?

<html>
<head>
<title>A jsp page</title>
</head>
<body>

//have written something and want to print this by java code

<input type="submit" value="print"/>// click here to print
</body>
</html>

回答by Ravi Bhojani

<input type="submit" value="print" onClick="window.print()"/> 

回答by raja777m

Please, try this one:

请试试这个:

<p class="print-align-right">
     <a href="#" onclick="javascript:window.print();" >Print this page</a>
</p>