当前位置: 代码迷 >> Java Web开发 >> 怎样把struts2 action的结果回到到jsp页面显示
  详细解决方案

怎样把struts2 action的结果回到到jsp页面显示

热度:270   发布时间:2016-04-14 09:16:12.0
怎样把struts2 action的结果返回到jsp页面显示
本人刚接触java,想问下怎样把 action的结果返回到jsp页面显示

下面是action的代码
package com.newthings.business.web;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;
import com.newthings.business.*;
import com.newthings.business.comm.espPKGone;
import com.newthings.business.comm.meter;

public class LoginAction extends ActionSupport{

private static final long serialVersionUID = 1L;
private String switchID;
private String gatewayIP;
private String CM;
meter m = new meter();
espPKGone esp = new espPKGone();


public String getSwitchID() {
return switchID;
}
public void setSwitchID(String switchID) {
this.switchID = switchID;
}


public String getGatewayIP() {
return gatewayIP;
}
public void setGatewayIP(String gatewayIP) {
this.gatewayIP = gatewayIP;
}


public String getCM() {
return CM;
}
public void setCM(String cM) {
CM = cM;
}

public void paraseChange(){

m.destID = Integer.parseInt(this.switchID, 16);
m.value = Integer.parseInt(this.CM, 16);
}

public String go(){
byte[] arr = null;
String result = "";

this.paraseChange();
arr = esp.wrCtrlwacth(m, this.gatewayIP);
for(int i = 0,num=arr.length;i <num ;i++){
      String hex = Integer.toHexString(arr[i]&0xff) + " ";          
      if(2 == hex.length()){//16杩涘埗鏁伴暱搴︿负2鏃讹紙16杩涘埗鏁?鈥?鈥濓級鍔?琛ヤ綅
            hex = '0' + hex;
          }
          result+=hex;
        }
result = "wrcontrol  meter: " + result;
System.out.println(result);
return SUCCESS;
}
}
怎样把sb的结果返回到welcom.jsp页面显示

login.jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title><s:text name="loginPage"/></title>
</head>
<body>
<s:form action="login">
            <s:textfield name="switchID" key="switchID"/>
            <s:textfield name="gatewayIP" key="gatewayIP"/>
             <s:textfield name="CM" key="command"/>
            
            <s:submit key="login"/>
</s:form>
</body>
</html>

welcom.jsp代码

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
    <head>
        <title><s:text name="succPage"/></title>
    </head>
    <body>
        <s:text name="success login">
<s:param>${sessionScope.user}</s:param>

</s:text><br>
    </body>
</html>


最后面是result的结果
------解决思路----------------------
呵呵 你试下看行不 可以的话就散分咯 哈哈 谢谢
------解决思路----------------------
 在action里面 获取request :HttpServletRequest request = ServletActionContext.getRequest();
  相关解决方案