小编nit*_*hin的帖子

为什么业务逻辑应该从JSP中移出?

将业务逻辑保留在JSP之外有什么好处,因为JSP主要用于表示?我们仍然看到在JSP中编写业务逻辑,因此我需要知道通过将业务逻辑移出JSP而获得的好处.

java jsp design-patterns servlets java-ee

18
推荐指数
2
解决办法
5980
查看次数

使用java从xml中删除包含实体的doctype

我正在尝试处理一个 xml,在此之前我需要从输入 xml 中删除文档类型和实体声明。

我正在使用以下代码删除文档类型和实体:

fileContent = fileContent.replaceAll("<!ENTITY ((.|\n|\r)*?)\">", "");
fileContent = fileContent.replaceAll("<!DOCTYPE((.|\n|\r)*?)>", "");
Run Code Online (Sandbox Code Playgroud)

这将删除实体,然后删除文档类型。如果 xml 在 xml 中包含以下 doctype 声明,这将正常工作:

<!DOCTYPE ichicsr SYSTEM "http://www.w3.org/TR/html4/frameset.dtd">

<!DOCTYPE ichicsr SYSTEM "D:\UPGRADE\NTServices\Server\\Xml21.dtd"
[<!ENTITY % entitydoc SYSTEM "D:\UPGRADE\NTServices\Server\\latin-entities.dtd"> %entitydoc;]>
Run Code Online (Sandbox Code Playgroud)

但是如果我有下面给出的文档类型,它就不起作用并且 xml 中的根标记被剥离:

<!DOCTYPE ichicsr SYSTEM "D:\UPGRADE\NTServices\Server\\Xml21.dtd" 
[<!ENTITY % entitydoc SYSTEM 'D:\UPGRADE\NTServices\Server\\Xml21.dtd'>
]> 
Run Code Online (Sandbox Code Playgroud)

如果我使用的正则表达式不正确或需要采取任何其他措施,请告诉我。

java regex xml string regular-language

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

使用javascript交换行

我有多个行,由for条件生成,上下两个图标.单击向上时,所选行应向上移动一步,单击向下所选行应向下移动一步

<html>
<head>
<body>
<form name="myForm">

 <table id="mainTable" border="1" width="100%">

   <script>
     document.write('<tr>')
     document.write('<td>')
     document.write('row1')
     document.write('</td>')
     document.write('</tr>')

     document.write('<tr>')
     document.write('<td>')
     document.write('row2')
     document.write('</td>')
     document.write('</tr>')
     document.write('</table>')

     document.write('<table>')
     document.write('<tr>')
     document.write('<td>')
     document.write('<input type="button" value=" move UP " onClick="swapRowUp(getRowIndex(this))"</input>')>
     document.write('<input type="button" value="move DOWN" onClick="swapRowDown(getRowIndex(this))"</input>')>
     document.write('</td>')
     document.write('</tr>')
     document.write('</table>')
</script>
 </table>

</form>
</body>
</head>
</html>
<script>
var mainTable = document.getElementById("mainTable"); 
function getRowIndex(el)
{
while( (el = el.parentNode) && el.nodeName.toLowerCase() !== 'tr' );

   if( el ) 
        alert(el.rowIndex);
        return el.rowIndex;
}

function swapRowUp(chosenRow) {
 if (chosenRow.rowIndex != 0) {
   moveRow(chosenRow, chosenRow.rowIndex-1); …
Run Code Online (Sandbox Code Playgroud)

html javascript

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

迭代hashmap

可能重复:
如何迭代Map中的每个条目?
如何迭代<String,POJO>的地图?

我编写了下面这段代码,但我仍然坚持迭代hashmap.

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

class demo
{
    public static void main(String v[]) {
        ArrayList<String> contactIds = new ArrayList<String>();
        contactIds.add("2");
        contactIds.add("3");

        HashMap names = new HashMap();
        names =  getNames(contactIds);

        // I want to get the total size of the hashmap  - names
        // for ex now there are 6 elements inside hashmap.
        // How can I get that count?

    }


    private static HashMap getNames(ArrayList contactIds) {
        HashMap names = new HashMap();
        String params …
Run Code Online (Sandbox Code Playgroud)

java collections hashmap

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