sturts的一个小问题 跟帖有分

superdcj 2011-03-05 01:38:41
在做文件上传,对于上传的不是图片类型进行判断,如果不是则重新输入。但是输入页面中有个select是通过一个action从数据库中取得数据的,所以说result 的input在配置时,不应该直接挑转到页面,而是应该跳转到action 但是现在说HTTP Status 404 - There is no Action mapped for namespace / and action name /getClasses.action.如果直接访问时可以的(直接输入action,则跳转到输入页面)。求解释。

struts配置。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.custom.i18n.resources" value="globalMessages" />

<package name="StudentManagement" extends="struts-default" namespace="/">
<action name="TeacherList" class="com.dcj.action.TeacherManagementAction" method="TeacherList">
<result name="success">admin/teacherManage.jsp</result>
</action>

<action name="addTeacher" class="com.dcj.action.TeacherManagementAction" method="addTeacher">
<result name="success" type="redirectAction">TeacherList</result>
</action>

<action name="getClasses" class="com.dcj.action.ClassManagementAction" method="getClasses">
<result name="success">teacher/addStudent.jsp</result>
</action>

<action name ="addStudent" class ="com.dcj.action.StudentManagementAction" >
<interceptor-ref name ="fileUpload" >
<param name="allowedTypes">image/bmp,image/png.image/jpeg,/image/gif</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"/>
<result name ="success" >student/studentInfo.jsp </result >
<result name ="input" type="chain">getClasses.action</result>
</action >

</package>


</struts>
...全文
216 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
feiyu107 2011-03-09
  • 打赏
  • 举报
回复
getTime()
返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数。
move01 2011-03-09
  • 打赏
  • 举报
回复
我上传下载都是用插件做的....挺好用的...
UPC_思念 2011-03-06
  • 打赏
  • 举报
回复
没搞明白问题,纯顶一下
superdcj 2011-03-06
  • 打赏
  • 举报
回复
来人啊。。。。
superdcj 2011-03-05
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 magicluo 的回复:]

引用 8 楼 superdcj 的回复:
你可能没弄懂我的意思,我都没有写update方法,我的add页面中,有数据是要从数据库中读出来的,直接访问add页面,select控件中是空的。所以要访问add页面,首先要访问得到数据的action,再跳转。关键是add页面出错后,我的result怎么配置。具体问题见6#


你在访问 add页面时候 ,填充其他的数据,你需要将你的action实……
[/Quote]我明白你的意思,prepare接口对于update和add操作时比较有用的,可以减少代码的重复,但是我现在时在页面上填充数据啊,执行action的前提是要有页面啊。我不是要对model进行数据填充,而是页面需要通过action得到填充,所以我觉得我的思路没错啊。。可能只是配置有问题。。。谁能再提供高见啊。。。
野生大猫 2011-03-05
  • 打赏
  • 举报
回复
你的 TYPE='CHAIN' 对应的是什么啊?
<result-type name='chain'>.....</..>

<result name='input' type='chain'>,,,,,,,,,,,,,,,,</...>

我感觉你的对应关系应该是搞错了

太长时间没接触了 错了不要笑话我! 谢谢

pmlxp 2011-03-05
  • 打赏
  • 举报
回复
<result name="success">../teacher/addStudent.jsp</result>

试试
magicluo 2011-03-05
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 superdcj 的回复:]
你可能没弄懂我的意思,我都没有写update方法,我的add页面中,有数据是要从数据库中读出来的,直接访问add页面,select控件中是空的。所以要访问add页面,首先要访问得到数据的action,再跳转。关键是add页面出错后,我的result怎么配置。具体问题见6#
[/Quote]

你在访问 add页面时候 ,填充其他的数据,你需要将你的action实现preparable接口

在prepare()方法中执行填充数据的逻辑.. 不要跳来跳去的
superdcj 2011-03-05
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 magicluo 的回复:]

引用 1 楼 superdcj 的回复:
另外,为了防止上传文件重名,imageFileName = new Date().getTime() + getExtention(fileName);
newData。getTime()为什么得到1299303883875这个值。


jdk的api说的都很明白。
getTime() 返回自 1970 年 1 月 1 日 00:00:00 ……
[/Quote]你可能没弄懂我的意思,我都没有写update方法,我的add页面中,有数据是要从数据库中读出来的,直接访问add页面,select控件中是空的。所以要访问add页面,首先要访问得到数据的action,再跳转。关键是add页面出错后,我的result怎么配置。具体问题见6#
magicluo 2011-03-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 superdcj 的回复:]
另外,为了防止上传文件重名,imageFileName = new Date().getTime() + getExtention(fileName);
newData。getTime()为什么得到1299303883875这个值。
[/Quote]

jdk的api说的都很明白。
getTime() 返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数

另外,你问题的处理方式很奇怪, crud 方法写一个action不就可以了
add和update 共享一个视图页面不就行了嘛? 提交页面有错就跳到当前的update 不就可以了撒

怎么跳来跳去的,不累啊...

superdcj 2011-03-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 magicluo 的回复:]

<result name ="input" type="chain">getClasses.action</result>


你这里直接getClasses就可以了吧? 不需要action后缀
[/Quote]这个说道要点了,但是又有一个新的问题,如果<result name ="input" type="chain">getClasses.action</result>它好像会去找getClasses.action中的input结果,显然,我需要的是getClasses.action success的结果,并把错误信息传过去,如何实现。如果chain改为redirectAction,错误信息就无法显示了。。。另外,对于1#的问题谁能解释一下啊。。。
magicluo 2011-03-05
  • 打赏
  • 举报
回复
<result name ="input" type="chain">getClasses.action</result>


你这里直接getClasses就可以了吧? 不需要action后缀
superdcj 2011-03-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yinbaicheng 的回复:]

问题描述不清楚
HTTP Status 404 - There is no Action mapped for namespace / and action name /getClasses.action
这个错误就是没找到对应的映射
[/Quote]是form提交返回input的时候,配置的转向action,但是提示出错。如果直接访问action是可以访问到的。。。
ybcwjj 2011-03-05
  • 打赏
  • 举报
回复
问题描述不清楚
HTTP Status 404 - There is no Action mapped for namespace / and action name /getClasses.action
这个错误就是没找到对应的映射
superdcj 2011-03-05
  • 打赏
  • 举报
回复
另外,为了防止上传文件重名,imageFileName = new Date().getTime() + getExtention(fileName);
newData。getTime()为什么得到1299303883875这个值。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧