因为医院项目里面的表名和字段名都为中文,要怎么办才能拿到呢
首先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());为在界面上取到的值
想问下解决办法
首先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());为在界面上取到的值
想问下解决办法
解决方案 »
- 这个怎么没有commit?
- jdbcTemplate 执行带返回参数存储过程的问题
- 听听大家意见!本人想学Jquery,问问应该看什么版本的.大家最常用的jquery是什么版本,用的人多吗?
- jdp语法问题?急,在线等!
- Eclipse问题!!高手请进!
- 有谁了解在线购买点卡,并对点卡进行充值的业务.都说说看啊.
- js32.lib and js32.dll
- 求教一个正则表达式的写法,
- jdbc远程连接服务器内网的oracle数据库,请各位大神指教
- Tomcat4配置一个web application出错
- 【求助】关于Extjs的 ,怎么从json里面 把值取出来?在线等!!!
- solr提交文档总是出错bad
不说这个,,,你的actionform属性和页面表单属性就不对应怎么可能取到
你from 提交的“记账代码” 你的actionform里没有这个属性,当然就拿不到啦
1.我是用实体点的字段名,actionform里面new出来的是这个实体,已经包括所有的字段了
2.公司的数据库的表名和字段名都是中文的,我木有办法改,只有去适应
3.属性和页面上的对应的,谢谢
数据库可以用中文,但建立对应的java实体类还是得用E文字母或数字、下划线啊