XsAction: package org.action; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import org.dao.imp.KcDao; import org.dao.imp.KcDaoImp; import org.dao.imp.XsDao; import org.dao.imp.XsDaoImp; import org.dao.imp.ZyDao; import org.dao.imp.ZyDaoImp; import org.model.*; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class XsAction extends ActionSupport{ KcDao kcDao; XsDao xsDao; private Xsb xs; private Kcb kcb; private File zpFile; private Zyb zyb; public File getZpFile(){ return zpFile; } public void setZpFile(File zpFile){ this.zpFile=zpFile; } public Kcb getKcb(){ return kcb; } public void setKcb(Kcb kcb){ this.kcb=kcb; } public Zyb getZyb(){ return zyb; } public void setZyb(Zyb zyb){ this.zyb=zyb; } public Xsb getXsb(){ return xs; } public void setXsb(Xsb xs){ this.xs=xs; } public String execute() throws Exception{ Map session=(Map)ActionContext.getContext().getSession(); Dlb user=(Dlb)session.get("user"); xsDao=new XsDaoImp(); Xsb xs=xsDao.getOneXs(user.getXh()); Map request=(Map)ActionContext.getContext().get("request"); request.put("xs", xs); return SUCCESS; } public String getImage() throws Exception{ xsDao=new XsDaoImp(); byte[] zp=xsDao.getOneXs(xs.getXh()).getZp(); HttpServletResponse response=ServletActionContext.getResponse(); response.setContentType("image/jpeg"); ServletOutputStream os=response.getOutputStream(); if(zp!=null&&zp.length>0){ for(int i=0;i<zp.length;i++){ os.write(zp[i]); } } return NONE; } public String updateXsInfo() throws Exception{ Map session=(Map)ActionContext.getContext().getSession(); Dlb user=(Dlb)session.get("user"); xsDao=new XsDaoImp(); ZyDao zyDao=new ZyDaoImp(); List zys=zyDao.getAll(); Xsb xs=xsDao.getOneXs(user.getXh()); Map request=(Map)ActionContext.getContext().get("request"); request.put("zys", zys); request.put("xs", xs); return SUCCESS; } public String updateXs() throws Exception{ xsDao=new XsDaoImp(); ZyDao zyDao=new ZyDaoImp(); Xsb stu=new Xsb(); stu.setXh(xs.getXh()); 102行 Set list=xsDao.getOneXs(xs.getXh()).getKcs(); stu.setKcs(list); stu.setXm(xs.getXm()); stu.setXb(xs.getXb()); stu.setCssj(xs.getCssj()); stu.setZxf(xs.getZxf()); stu.setBz(xs.getBz()); Zyb zy=zyDao.getOneZy(zyb.getId()); stu.setZyb(zy); if(this.getZpFile()!=null){ FileInputStream fis=new FileInputStream(this.getZpFile()); byte[] buffer=new byte[fis.available()]; fis.read(buffer); stu.setZp(buffer); } xsDao.update(stu); return SUCCESS; } public String getXsKcs() throws Exception{ Map session=(Map)ActionContext.getContext().getSession(); Dlb user=(Dlb)session.get("user"); xsDao=new XsDaoImp(); String xh=user.getXh(); Xsb xsb=xsDao.getOneXs(xh); Set list=xsb.getKcs(); Map request=(Map)ActionContext.getContext().get("request"); request.put("list", list); return SUCCESS; } public String deleteKc() throws Exception{ Map session=(Map)ActionContext.getContext().getSession(); String xh=((Dlb)session.get("user")).getXh(); xsDao=new XsDaoImp(); Xsb xs2=xsDao.getOneXs(xh); Set list=xs2.getKcs(); Iterator iter=list.iterator(); while(iter.hasNext()){ Kcb kc2=(Kcb)iter.next(); if(kc2.getKch().equals(kcb.getKch())){ iter.remove(); } } xs2.setKcs(list); xsDao.update(xs2); return SUCCESS; } public String selectKc() throws Exception{ Map session=(Map)ActionContext.getContext().getSession(); String xh=((Dlb)session.get("user")).getXh(); xsDao=new XsDaoImp(); Xsb xs3=xsDao.getOneXs(xh); Set list=xs3.getKcs(); Iterator iter=list.iterator(); while(iter.hasNext()){ Kcb kc3=(Kcb)iter.next(); if(kc3.getKch().equals(kcb.getKch())){ return ERROR; } } list.add(new KcDaoImp().getOneKc(kcb.getKch())); xs3.setKcs(list); xsDao.update(xs3); return SUCCESS; } } struts.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuaration 2.3//EN" "http://struts.apache.org//dtds/struts-2.3.dtd"> <struts> <package name="default" extends="struts-default"> <action name="login" class="org.action.LoginAction"> <result name="success">/main.jsp</result> <result name="error">/login.jsp</result> </action> <action name="xsInfo" class="org.action.XsAction"> <result name="success">/xsInfo.jsp</result> </action> <action name="getImage" class="org.action.XsAction" method="getImage"> </action> <action name="updateXsInfo" class="org.action.XsAction" method="updateXsInfo"> <result name="success">/updateXsInfo.jsp</result> </action> <action name="updateXs" class="org.action.XsAction" method="updateXs"> <result name="success">/updateXs_success.jsp</result> </action> <action name="getXsKcs" class="org.action.XsAction" method="getXsKcs"> <result name="success">/xsKcs.jsp</result> </action> <action name="deleteKc" class="org.action.XsAction" method="deleteKc"> <result name="success">/deleteKc_success.jsp</result> </action> <action name="getAllKc" class="org.action.KcAction"> <result name="success">/allKc.jsp</result> </action> <action name="selectKc" class="org.action.XsAction" method="selectKc"> <result name="success">/selectKc_success.jsp</result> <result name="error">/selectKc_fail.jsp</result> </action> </package> </struts> updateXsInfo。jsp: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s" %> <% 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>学生选课系统</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 bgcolor="#D9DFAA"> <s:set name="xs" value="#request.xs"></s:set> <s:form action="updateXs.action" method="post" enctype="multipart/form-data"> <table> <tr> <td>学号:</td> <td><input type="text" name="xs.xh" value="<s:property value="#xs.xh"/>"readonly/> </td></tr> <tr> <td>姓名:</td> <td><input type="text" name="xs.xm" value="<s:property value="#xs.xm"/>"/></td> </tr> <tr> <s:radio list="#{1:""男"",0:""女"" }" value="#xs.xb" name="xs.xb" label="性别"></s:radio> </tr> <tr> <td>专业:</td> <td> <select name="zyb.id"> <s:iterator id="zy" value="#request.zys"> <option value="<s:property value="#zy.id"/>"> <s:property value="#zy.zym"/></option> </s:iterator> </select> </td> </tr> <tr> <td>出生时间:</td> <td><input type="text" name="xs.cssj" value="<s:date name="#xs.cssj" format="yyyy-MM-dd"/>"/></td> </tr> <tr> <td>备注:</td> <td><input type="text" name="xs.bz" value="<s:date name="#xs.bz"/>"/></td> </tr> <tr> <td>总学分:</td> <td><input type="text" name="xs.zxf" value="<s:property value="#xs.zxf"/>"/></td> </tr> <tr> <td>照片:</td> <td><input type="file" name="zpFile"/></td> </tr> <tr> <td><input type="submit" value="修改"/></td> </tr> </table> </s:form> </body> </html> |
|
5分 |
,XsAction.updateXs()哪里调试下,看看那个值没有传过来(或是NULL), 最好贴控制台的报错信息,页面中的报错信息不详细
|
– -控制台关键是没报错啊九月 03, 2014 12:53:22 下午 org.apache.jasper.compiler.TldLocationsCache tldScanJar
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 这个算么- – |
|
我打印了一下,发现xs为空- -为什么啊,我jsp里代码写错了么
|
|
10分 |
xs.getXh() 这个xs 应该是为空的
|
重新获取一次xs试下
|
|
具体如何添加呢,我不管怎么获取还是不对,新手一枚。 |
|
stu.setXh(xs.getXh()); <span style=”color: #FF0000;”>102行</span>
这里错了,xs是空的,你直接定义一个这样的对象,又没有去给它赋值,你还想拿东西,你太霸道了… |
|
xs的set和get方法是不是有问题啊,你直接工具生成下,不要手写
|
|
你updateXsInfo() 里面不是 获取了一遍么 |
|
25分 |
你定义的变量为private Xsb xs; setter getter方法是setXsb getXsb 前台页面又是xs,相当于你定义的xs没有setter、getter方法;后台当然取不到页面中的值了
|
恩,刚才试过了,11楼正解,是我太不小心了,谢谢啊 |
|
谢谢啦。问题解决了。自己粗心了 |