因为医院项目里面的表名和字段名都为中文,要怎么办才能拿到呢
首先JSP界面:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic" %>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>    <form action="my.do?method=findall" method="post">
     <input type="text" name="zyzydjb.记帐代码" ><br>
     <input type="text" name="userEntity.name" ><br>
     <input type="submit" value="提交" ><br>
     <br>
    </form>
  </body>
</html>
然后是actionform:
package com.yhj.util;import org.apache.struts.action.ActionForm;import com.yhj.entity.UserEntity;
import com.yhj.entity.住院住院登记表;@SuppressWarnings("serial")
public class MyActionForm extends ActionForm {
private UserEntity userEntity=new UserEntity();

public UserEntity getUserEntity() {
return userEntity;
} public void setUserEntity(UserEntity userEntity) {
this.userEntity = userEntity;
} private 住院住院登记表 zyzydjb = new 住院住院登记表(); public 住院住院登记表 getZyzydjb() {
return zyzydjb;
} public void setZyzydjb(住院住院登记表 zyzydjb) {
this.zyzydjb = zyzydjb;
}}
最后是action:
package com.yhj.action;import java.util.List;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;import com.yhj.biz.MyBiz;
import com.yhj.entity.住院住院登记表;
import com.yhj.util.MyActionForm;public class MyAction extends DispatchAction { private MyBiz mb; public void setMb(MyBiz mb) {
this.mb = mb;
} public ActionForward findall(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
MyActionForm maf = (MyActionForm) form;
System.out.println(maf.getZyzydjb().get记帐代码());
System.out.println(maf.getUserEntity().getName());
//List<住院住院登记表> list = mb.selectZyDjb();
//request.setAttribute("list", list);
return null;
//return mapping.findForward("success");
}
}打印的结果是:
System.out.println(maf.getZyzydjb().get记帐代码());为null,没拿到值
System.out.println(maf.getUserEntity().getName());为在界面上取到的值
想问下解决办法

解决方案 »

  1.   

    住院住院登记表???汉字做类名?
    不说这个,,,你的actionform属性和页面表单属性就不对应怎么可能取到
      

  2.   

    用汉字做类名?还真是奇葩!!
    你from 提交的“记账代码” 你的actionform里没有这个属性,当然就拿不到啦
      

  3.   

    我想再补充一下:
    1.我是用实体点的字段名,actionform里面new出来的是这个实体,已经包括所有的字段了
    2.公司的数据库的表名和字段名都是中文的,我木有办法改,只有去适应
    3.属性和页面上的对应的,谢谢
      

  4.   

    你看看  住院住院登记表 zyzydjb  各个字段的setter和getter方法是否有啊?
      

  5.   

    中文作标识符,你以为是VB啊
    数据库可以用中文,但建立对应的java实体类还是得用E文字母或数字、下划线啊
      

  6.   

    怎么用英文你告诉我一下,hibernate倒进来的表不都数据库里面的表名和字段名一样么?怎么改成英文,你给我改个试试,给我发段代码,灰常感谢
      

  7.   

    应该是配置文件不正确吧!可以检查一下.XML文件,代码应该没有什么问题!
      

  8.   

    我突然忘了struts1了,多谢提醒,struts2用惯了