偶的项目错误记载

myhalfsea posted @ 2011年4月07日 11:35 in JAVA , 1427 阅读

2011/04/05   关于struts2的错误

我用struts2和hibernate3、dwr来做毕业设计,原以为周多一周局可以搞定,但有两个错误却让我检查了3天。

1、看代码

public class Login extends ActionSupport {
    Login(){
        System.out.println("xxxxxxxxxxxx");
    }
    public String pointLogin(){
        HttpServletRequest request=ServletActionContext.getRequest();
        String userid = request.getParameter("userid");
        String password = request.getParameter("password");
        System.out.println(userid+": " + password);
        return "success";
    }
}

   这是我用于测试登录页是否能正确跳转的代码,你发现那里错了吗?

   一般情况下,他是没错的,但是在struts2框架下,该项目根本无法启动!为什么?因为构造方法是默认权限(default),且看default权限的描述:默认权限(default)类,数据成员,构造方法,方法成员,都能够使用默认权限,即不写任何关键字。默认权限即同包权限,同包权限的元素只能在定义它们的类中,以及同包的类中被调用。  不仅仅default不可以,protected也不可以。所以,如果你一定要写构造方法,那么请加上public。

2、先看看struts2.xml配置文件:

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

<struts>
    <constant name="struts.i18n.encoding" value="UTF-8"></constant>
    <constant name="struts.locale" value="zh_CN"></constant>
    <package name="count" namespace="/count" extends="struts-default">
        <interceptors>
            <interceptor name="userInterceptor" class="com.common.UserInterceptor"></interceptor>
            <interceptor-stack name="myInstance">
                <interceptor-ref name="defaultStack"></interceptor-ref>
                <interceptor-ref name="userInterceptor"></interceptor-ref>
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="myInstance"></default-interceptor-ref>
        <global-results>
            <result name="error">login.jsp</result>
        </global-results>
        <action name="login" class="com.action.Login" method="pointLogin">
            <result name="success">WEB-INF/jsp/content.jsp</result>
            <result name="error">login.jsp</result>
        </action>
    </package>

</struts>

这段代码有错吗?没有!我也是这么觉得的。但是出现一个问题:在我点击“登录”按钮后,页面跳转了,Login()构造方法也也执行了,但是却是空白页面,查看源代码也是神马也木有!我找哇找,重写了4个project,最后我把struts.xml中关于拦截器的代码注释了,然后就好了……啊啊啊……啊啊……啊……………………我表示,我的拦截器里面神马也没写,我就是先配置好,放在那儿也不行哇!!!他就那样给我全过滤了!血的教训……………………

 

edpost.in 说:
2023年4月16日 16:14

Our team comprises of professional writers & citizen journalists with diverse range of interest in Journalism who are passionate about publishing the Education Updates with transparency in general public interest. edpost.in edpost is a initiative of professional writers who have come together for dedicated news coverage of latest happenings around the country (India).


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta
Butterfly Theme | Design: HRS Hersteller of mobile Hundeschule.