应用系统具体问题

所有空间

产品规划
AOM百科
知识共享

导航
目录

FAQ

关于如何在liteBean中动态创建组件

例如建立一个panel组件,代码如下:

   Application app = FacesContext.getCurrentInstance().getApplication();
   UIPanel uipanel = (UIPanel) app.createComponent(UIPanel.COMPONENT_TYPE);

基于AOM、Spring、Hibernate构建应用时增删改时出现异常的解决方法

增删改时出现以下异常:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.在applicationContext.xml加入以下代码即可:XXXService是你要注入的Service名

applicationContext.xml
   <bean id="baseTransaction"
		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
		abstract="true">
		<property name="transactionManager" ref="transactionManager"/>
		<!--  
		<property name="proxyTargetClass" value="true"/>-->
		<property name="transactionAttributes">
		<props>
		<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
		<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
		<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
		<prop key="save*">PROPAGATION_REQUIRED</prop>
		<prop key="add*">PROPAGATION_REQUIRED</prop>
		<prop key="update*">PROPAGATION_REQUIRED</prop>
		<prop key="remove*">PROPAGATION_REQUIRED</prop>
		<prop key="modify*">PROPAGATION_REQUIRED</prop>
		<prop key="create*">PROPAGATION_REQUIRED</prop>
		</props>
		</property>
	</bean>

	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	<tx:annotation-driven transaction-manager="transactionManager" />

	<bean id="txManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>


	<bean id="XXXXXXService" parent="baseTransaction"
		class="org.demo.XXXXXXService">
		<property name="sessionFactory" ref="sessionFactory" />
		
	</bean>

AOM环境下怎样获取客户端IP和MAC地址

获取客户端IP
   public String getMyIP() {
      try {
          FacesContext fc = FacesContext.getCurrentInstance();
          HttpServletRequest request = (HttpServletRequest)fc.getExternalContext().getRequest();
          return request.getRemoteAddr();
      }catch (Exception e) {
          e.printStackTrace();
      }
      return "";
   }
获取客户端MAC
   public String getMACAddress(String ip){
      String str = "";
      String macAddress = "";
      try {
          Process p = Runtime.getRuntime().exec("nbtstat -A " + ip);
          InputStreamReader ir = new InputStreamReader(p.getInputStream());
          LineNumberReader input = new LineNumberReader(ir);
          for (int i = 1; i < 100; i++) {
               str = input.readLine();
               if (str != null) {
                   if (str.indexOf("MAC Address") > 1) {
                      macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
                      break;
                   }
               }
           }
      } catch (IOException e) {
          e.printStackTrace(System.out);
      }
      return macAddress;
  }

从requestMap中取中文参数出现乱码

场景描述:修改了Apusic 应用服务器中apusic.conf配置文件,配置了URIEncoding参数为GBK,从requestMap中取中文参数出现乱码。
Apusic应用服务器的apusic.conf文件的修改为:给com.apusic.web.WebService类添加了URIEncoding属性,设置其value值为GBK。具体内容如下:

<SERVICE
    CLASS="com.apusic.web.WebService"
    >
    <ATTRIBUTE NAME="MaxWaitingClients" VALUE="500"/>
    <ATTRIBUTE NAME="WaitingClientTimeout" VALUE="5"/>
    <ATTRIBUTE NAME="KeepAlive" VALUE="true"/>
    <ATTRIBUTE NAME="KeepAliveTimeout" VALUE="15"/>
    <ATTRIBUTE NAME="MaxKeepAliveRequests" VALUE="100"/>
    <ATTRIBUTE NAME="MaxKeepAliveConnections" VALUE="300"/>
    <ATTRIBUTE NAME="NumberSelectors" VALUE="1"/>
    <ATTRIBUTE NAME="ServletReloadCheckInterval" VALUE="3"/>
    <ATTRIBUTE NAME="EnableLog" VALUE="False"/>
    <ATTRIBUTE NAME="LogFileName" VALUE="logs/access.log"/>
    <ATTRIBUTE NAME="LogFileLimit" VALUE="1000000"/>
    <ATTRIBUTE NAME="LogFileCount" VALUE="10"/>

    <ATTRIBUTE NAME="URIEncoding" VALUE="GBK"/>
</SERVICE>

页面带参数的格式为:url="test1.faces?name=中国"
解决方案为:
添加一个filter拦截此类请求,将FaceletViewHandler.CHARACTER_ENCODING_KEY从sessionMap中删除,具体实现为:

TestBean.java
public class FixedEncodingFilter implements Filter {

	public void destroy() {
		// do nothing
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpSession session = ((HttpServletRequest) request).getSession(false);
		if (session != null) {
			session.removeAttribute(FaceletViewHandler.CHARACTER_ENCODING_KEY);
		}
		chain.doFilter(request, response);
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		// do nothing
	}

}
输入标签加入到本页面中
Please wait 
寻找标签吗?请输入搜索信息.