sshforjava
① java SSH 求解,在線等待~如果有可運行項目(ssh,不要求業務),求參考 [email protected]
呃 我用的是S2SH
幫不了你了
② 求一個SSH框架的JAVAWEB項目
首先將下面代碼COPY下來寫成一個js;
<!-- 開始-->
//自動補全
//autoInput 自動補全輸入組件ID
//自動補全UL列表ID
function AutoComplete(autoInputId, autoULId) {
var child = null;
//獲取伺服器數據value文本框輸入值,list資料庫返回集合,valueProperty使用list對象的那個屬性作為vlaue值
this.autoComplete = function (value,list) {
//清空上次數據
DWRUtil.removeAllOptions(autoULId);
if (child != null && value == child.innerHTML) {
return;
}
if (value == "") {
return;
}
child = null;
if (list.length > 0) {
$(autoULId).style.display = "block";
for (i = 0; i < list.length; i++) {
var title = list[i];
var li = document.createElement("li");
li.ondblclick = function () {
child = li;
$(autoInputId).value = li.innerHTML;
$(autoULId).style.display = "none";
};
li.innerHTML =title;//li.innerHTML 表示資料庫中的tname
//alert(li.innerHTML);
$(autoULId).appendChild(li);
}
} else {
$(autoULId).style.display = "none";
}
};
//當按下上下按鈕的時候選中數據
window.document.onkeydown = function () {
var key = window.event.keyCode;
//向下
if (key == 40) {
if (child == null) {
var nextNode = $(autoULId).firstChild;
if (nextNode != null) {
child = nextNode;
child.style.backgroundColor = "powderblue";
}
} else {
var nextNode = child.nextSibling;
if (nextNode != null) {
child.style.backgroundColor = "";
child = child.nextSibling;
child.style.backgroundColor = "powderblue";
}
}
//向上
} else {
if (key == 38) {
if (child != null) {
var previousNode = child.previousSibling;
if (previousNode != null) {
child.style.backgroundColor = "";
child = child.previousSibling;
child.style.backgroundColor = "powderblue";
}
}
} else {
if (key == 13) {
if (child != null) {
$(autoInputId).value = child.innerHTML;
$(autoULId).style.display = "none";
}
}
}
}
};
//設置補全數據位置
window.onload = function () {
var oRect = $(autoInputId).getBoundingClientRect();
$(autoULId).style.left = oRect.left - 42;
$(autoULId).style.top = oRect.top + 20;
};
}
<!--結束--> 如果以上js保存不起就將js的編碼改為gbk(JS右鍵屬性就是了),
<!-- 關於上面這個Js你就不要問我為什麼了。因為我也不知道 。我只知道我要用的時候我導進來就行了-->
現在就要看jsp頁面了:
1.首先:導入上面寫入的js,然後在web.xml去配置,然後再在IE中進去測試。找到其它的js.
2.寫入以下樣式
<style type="text/css">
.aul{list-style-type: none;width: 150px;position: absolute;display: none;}
.aul li{background-color: expression(sourceIndex%2==0?'lavender':'beige')}
</style>
3.函數以及回調函數如下:
<script type="text/javascript">
//創建自動補全對象
var auto= new AutoComplete('dictType','ul1'); //前面一個是input的id,後一個就是ui的id咯
function autoName(value){
DWRService.findTypeByName(value, // DWRService是在dwr.xml中的名稱.. findTypeByName是Biz中的方法///方法根據輸入的值進行like查詢返回list
function(list){
auto.autoComplete(value,list);
});
}
</script> 4.最後一步: //下面這個input是你輸入的框要補的那個.. (表示不清..不知道怎麼說)
<input type="text" name="basDict.dictType" id="dictType"
onpropertychange="autoName(this.value)">
<ul class="aul" id="ul1" style="cursor:pointer;"> <!--一定是普通的標簽..ui是呆會查詢符合條件的值顯示的位置> <!--上面這些代碼是我從我前幾天做的項目中下來的。
如果你按我這種方式去實現Ajax去實現的話有什麼不明白的。可以問我。不過我這幾天白天都在做項目,最好晚上留言給我。 呵。不好意思啊。。
再說明一下,整個我都是用dwr框架去實現的/.---->
biz方法如下:
public List findTypeByName(String tName) {
String hql = "select distinct d.dictType from BasDict as d where d.dictType like '%"+tName+"%'";
return super.getHibernateTemplate().find(hql);
} dwr.xml配置如下:
<dwr>
<allow>
<create creator="spring" javascript="DWRService">
<param name="beanName" value="BasDictBiz"/>
</create>
</allow>
</dwr> 要是做出來效果你不滿意你可以改一下jsp上的頁面上的代碼。使下拉的更漂亮
③ java ssh項目更新問題,先查詢數據,然後進行更新操作,為什麼保存不成功下面有代碼和控制台的一些信息
不知道你項目使用ssh框架沒 應該是數據沒持久化到資料庫中哦就是事物沒提交哦
如果使用了ssh框架那麼看下spring配置文件是否配置了事物提交以及方法名是否命名錯誤了
④ java ssh開發,點擊系統內一個按鈕,功能是跳轉到一個頁面,出現如下錯誤,求解決:
給jvm分配的內存太少了。
對於絕大多數應用來說,Java堆是虛擬機管理最大的一塊內存。Java堆是被所有線程共享的,在虛擬機啟動時創建。Java堆的唯一目的就是存放對象實例,絕大部分的對象實例都在這里分配。這一點在VMSpec中的描述是:所有的實例以及數組都在堆上分配(原文:sisallocated),但是在逃逸分析和標量替換優化技術出現後,VMSpec的描述就顯得並不那麼准確了。
Java堆內還有更細致的劃分:新生代、老年代,再細致一點的:eden、fromsurvivor、tosurvivor,甚至更細粒度的本地線程分配緩沖(TLAB)等,無論對Java堆如何劃分,目的都是為了更好的回收內存,或者更快的分配內存,在本章中我們僅僅針對內存區域的作用進行討論,Java堆中的上述各個區域的細節,可參見本文第二章《JVM內存管理:深入垃圾收集器與內存分配策略》。
根據VMSpec的要求,Java堆可以處於物理上不連續的內存空間,它邏輯上是連續的即可,就像我們的磁碟空間一樣。實現時可以選擇實現成固定大小的,也可以是可擴展的,不過當前所有商業的虛擬機都是按照可擴展來實現的(通過-Xmx和-Xms控制)。如果在堆中無法分配內存,並且堆也無法再擴展時,將會拋出OutOfMemoryError異常。
調高內存還不行,需要檢查一下代碼中是否有死循環存在,context的配置是否合理是否會造成死循環。
⑤ ssh出現的問題:java.lang.IllegalStateException
好長時間沒寫ssh了。你用tamcat幾?如果是7的話,換一個6試試。
⑥ 如何導入ganymed ssh-2 for java.jar
先創建一個基於maven的項目,點擊打開pom.xml文件
點擊Dependencies標簽頁,然後點擊Dependencies中的add按鈕,輸入想添加的jar包名字,就會出現下會把對應名稱的所有版本jar包列出來
點擊OK之後,在pom.xml會帶回jar包的信息,type表示依賴包的類型,Scope表示這個依賴包的作用周期
保存後install maven,然後再點開項目中的Maven Dependencies就會發現多了相應的jar包了
⑦ ssh框架下,java代碼 頁面分頁 ,怎麼讀取list序列的第n個元素
取第二頁的數據時,將當前頁,傳給action,action再調用層,拿到指定范圍的數據。
hql這樣限制:setFirstResult(開始取數據的位置);setMaxResult(取數據的數量;
返回到jsp頁面後是一個集合。比如寫條數據記錄在表格的每行上,就在表格的行上做循環,
<%
for(int i=0;i<resultList.size();i++) {
%>
表格行的代碼。。。。
<%
}
%>
⑧ java連接ssh登陸路由器
packagecom.flyingzl.ssh;importjava.util.ArrayList
importjava.util.Hashtable
importjava.util.List
importorg.apache.log4j.Logger
importorg.apache.oro.text.regex.MalformedPatternException
importcom.jcraft.jsch.ChannelShell
importcom.jcraft.jsch.JSch
importcom.jcraft.jsch.Session
importcom.jcraft.jsch.UserInfo
importexpect4j.Closure
importexpect4j.Expect4j
importexpect4j.ExpectState
importexpect4j.matches.EofMatch
importexpect4j.matches.Match
importexpect4j.matches.RegExpMatch
importexpect4j.matches.TimeoutMatch
publicclassShell{privatestaticLoggerlog=Logger.getLogger(Shell.class)
privateSessionsession
privateChannelShellchannel
privatestaticExpect4jexpect=null
=1000
privateStringBufferbuffer=newStringBuffer()
publicstaticfinalintCOMMAND_EXECUTION_SUCCESS_OPCODE=-2
_R=" "
_N=" "
publicstaticfinalStringCOLON_CHAR=":"
publicstaticStringENTER_CHARACTER=BACKSLASH_R
publicstaticfinalintSSH_PORT=22
//正則匹配,用於處理伺服器返回的結果publicstaticString[]linuxPromptRegEx=newString[]{"~]#","~#","#",":~#","/$",">"}
publicstaticString[]errorMsg=newString[]{"couldnotacquiretheconfiglock"}
//ssh伺服器的ip地址privateStringip
//ssh伺服器的登入埠privateintport
//ssh伺服器的登入用戶名privateStringuser
//ssh伺服器的登入密碼privateStringpassword
publicShell(Stringip,intport,Stringuser,Stringpassword){this.ip=ip
this.port=port
this.user=user
this.password=password
expect=getExpect()
}/***關閉SSH遠程連接*/publicvoiddisconnect(){if(channel!=null){channel.disconnect()
}if(session!=null){session.disconnect()
}}/***獲取伺服器返回的信息*@return服務端的執行結果*/publicStringgetResponse(){returnbuffer.toString()
}//獲得Expect4j對象,該對用可以往SSH發送命令請求privateExpect4jgetExpect(){try{log.debug(String.format("Startloggingto%s@%s:%s",user,ip,port))
JSchjsch=newJSch()
session=jsch.getSession(user,ip,port)
session.setPassword(password)
Hashtable<String,String>config=newHashtable<String,String>()
config.put("StrictHostKeyChecking","no")
session.setConfig(config)
localUserInfoui=newlocalUserInfo()
session.setUserInfo(ui)
session.connect()
channel=(ChannelShell)session.openChannel("shell")
Expect4jexpect=newExpect4j(channel.getInputStream(),channel.getOutputStream())
channel.connect()
log.debug(String.format("Loggingto%s@%s:%ssuccessfully!",user,ip,port))
returnexpect
}catch(Exceptionex){log.error("Connectto"+ip+":"+port+"failed,!")
ex.printStackTrace()
}returnnull
}/***執行配置命令*@paramcommands要執行的命令,為字元數組*@return執行是否成功*/publicbooleanexecuteCommands(String[]commands){//如果expect返回為0,說明登入沒有成功if(expect==null){returnfalse
}log.debug("----------:----------")
for(Stringcommand:commands){log.debug(command)
}log.debug("----------End----------")
Closureclosure=newClosure(){publicvoidrun(ExpectStateexpectState)throwsException{buffer.append(expectState.getBuffer())
//bufferisstring//bufferforappending//outputofexecuted//commandexpectState.exp_continue()
}}
List<Match>lstPattern=newArrayList<Match>()
String[]regEx=linuxPromptRegEx
if(regEx!=null&®Ex.length>0){synchronized(regEx){for(StringregexElement:regEx){//listofregxlike,:>,/>//etc.itispossible//commandpromptsofyour//remotemachinetry{RegExpMatchmat=newRegExpMatch(regexElement,closure)
lstPattern.add(mat)
}catch(MalformedPatternExceptione){returnfalse
}catch(Exceptione){returnfalse
}}lstPattern.add(newEofMatch(newClosure(){//shouldcause//entirepagetobe//collectedpublicvoidrun(ExpectStatestate){}}))
lstPattern.add(newTimeoutMatch(defaultTimeOut,newClosure(){publicvoidrun(ExpectStatestate){}}))
}}try{booleanisSuccess=true
for(StringstrCmd:commands){isSuccess=isSuccess(lstPattern,strCmd)
}//防止最後一個命令執行不了isSuccess=!checkResult(expect.expect(lstPattern))
//找不到錯誤信息標示成功Stringresponse=buffer.toString().toLowerCase()
for(Stringmsg:errorMsg){if(response.indexOf(msg)>-1){returnfalse
}}returnisSuccess
}catch(Exceptionex){ex.printStackTrace()
returnfalse
}}//檢查執行是否成功privatebooleanisSuccess(List<Match>objPattern,StringstrCommandPattern){try{booleanisFailed=checkResult(expect.expect(objPattern))
if(!isFailed){expect.send(strCommandPattern)
expect.send(" ")
returntrue
}returnfalse
}catch(MalformedPatternExceptionex){returnfalse
}catch(Exceptionex){returnfalse
}}//檢查執行返回的狀態privatebooleancheckResult(intintRetVal){if(intRetVal==COMMAND_EXECUTION_SUCCESS_OPCODE){returntrue
}returnfalse
}//登入SSH時的控制信息//設置不提示輸入密碼、不顯示登入信息等{Stringpasswd
publicStringgetPassword(){returnpasswd
}publicbooleanpromptYesNo(Stringstr){returntrue
}publicStringgetPassphrase(){returnnull
}publicbooleanpromptPassphrase(Stringmessage){returntrue
}publicbooleanpromptPassword(Stringmessage){returntrue
}publicvoidshowMessage(Stringmessage){}}}