现在的位置: 首页 > 综合 > 正文

Struts开发问题集锦

2014年02月03日 ⁄ 综合 ⁄ 共 2141字 ⁄ 字号 评论关闭

1.Could not load class Interceptor2/Myinterceptor. Perhaps it exists but certain dependencies are not available? - interceptor 

解决:缺少log4j.jar

2.当你的action处理类继承ActionSupport时

public class Reg extends ActionSupport{
private String username;
private String mymsg;
private String password1;
private String password2;
private Date birthday;

public String execute() throws Exception {}

form表单的action一定加上“.action”<s:form id="id" action="Interceptor2/reg.action">

否则出现

type Status report

message /Test/xInterceptor2/reg.jsp

description The requested resource (/Test/xInterceptor2/reg.jsp) is not available.错误

3

在struts2de 1.6以前版本,都是用<s:datepicker>标签来获取时间,1.8后可以用struts-dojo.plugin里的<sx:datetimepicker>标签获取时间。

1).struts2-dojo-plugin-2.1.6.jar引入到自己的项目中。 
2).jsp中加入如下内容 
<%@ page language="java" pageEncoding="UTF-8"%> 
<%@ taglib prefix="s" uri="/ struts-tags" %> 
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %> 
3). <head>中加入下列 

<head> 
    <s:head theme="xhtml"/> 
    <sx:head parseContent="true"/>       
</head> 
4).页面中使用 
<sx:datetimepicker name="birthday" lable="请求时间" displayFormat="yy-MM-dd" />

4.Struts-xml路径的跳转和命名空间的设置问题

<package name="helloworld" namespace="/base" extends="struts-default">
        
        <action name="helloWorldAction" class="action.HelloWorldAction">
        
            <result name="success">/success.jsp</result>
        </action>
    </package>

以上的代码,设置的命名空间为base,但是此时跳转的页面success.jsp位于项目根路径下,如果前面没有“/”,则会认为success.jsp位于根路径的base文件夹下

在struts2de 1.6以前版本,都是用<s:datepicker>标签来获取时间,1.8后可以用struts-dojo.plugin里的<sx:datetimepicker>标签获取时间。

1).struts2-dojo-plugin-2.1.6.jar引入到自己的项目中。 
2).jsp中加入如下内容 
<%@ page language="java" pageEncoding="UTF-8"%> 
<%@ taglib prefix="s" uri="/ struts-tags" %> 
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %> 
3). <head>中加入下列 

<head> 
    <s:head theme="xhtml"/> 
    <sx:head parseContent="true"/>       
</head> 
4).页面中使用 
<sx:datetimepicker name="birthday" lable="请求时间" displayFormat="yy-MM-dd" />

4.Struts-xml路径的跳转和命名空间的设置问题

<package name="helloworld" namespace="/base" extends="struts-default">
        
        <action name="helloWorldAction" class="action.HelloWorldAction">
        
            <result name="success">/success.jsp</result>
        </action>
    </package>

以上的代码,设置的命名空间为base,但是此时跳转的页面success.jsp位于项目根路径下,如果前面没有“/”,则会认为success.jsp位于根路径的base文件夹下

抱歉!评论已关闭.