从头来一遍
拦截器有点迷糊
还行没太乱
被一个无关紧要的类搞蒙圈了
1
先写一个拦截器
在web里,一般这么写 public class LoginInterceptor extends AbstractInterceptor
下一个是方法
Public String intercept(ActionInvocation arg0)throws Exception
{
开始巴拉巴拉操作
如果成功 就放行
Arg0.invoke();
如果不成功,就自己返回个语句
Return “不可以咩~”
}
2
Ok,拦截器写完了 让我们红尘作伴开始配置
配置的套路是这样的 在Struts.xml里
<interceptors>
<interceptor name=”logincheck” class=”芭啦芭啦”>(好像不用写方法哦~)
</interceptors>
(不行我得写会这单词 interceptors interceptor interceptor interceptor interceptor interceptor interceptor interceptors)
好了接着写虽然明天估计又忘了。。。
然后开始action了啊
<action name class method>(这都老套路)
<interceptor-ref name=”logincheck”></interceptor-ref>
<result></result>
</action>
Ok~O(∩_∩)O~好像差不多了 去试一下~
忘怎么取Session了 哭T,T 又不争气的回来了
1
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
2
HttpSession session = ServletActionContext.getRequest();
一顿找jar包的错最后发现是ServletActionContext!!不是ServletContext
够了~!
好了同学们让我们走一个~
失败了宝宝有点蒙。。。
从头说一遍
运用Session在登录上没有任何意义啊~!
因为 打开一个新界面:登录不进去(因为Session的缘故)
老界面:完全没意义
(而且直接登录success.jsp拦截器我还不知道怎么起作用)
Ok~完美差不多了也不写了,
晚上回来把那个作业写了,再把什么国际配置弄明白就行了,如果不偷懒的话
还有写界面挖出来的坑,
两个select语句还是不熟悉啊
第一个是查单个
Return qr.query(“select * from user where name=?” , new BeanHeadler<User>(User.class),user.getName());
第二个是查一个集合
Return qr.query(“select * from user where name=?,new Object[]{user.getName()},new BeanListHeadler<User>(User.class);
然后是C3p0链接数据库我也记不住啊/(ㄒoㄒ)/~~
先链接C3P0的配置文件
然后写个C3P0Utils类
Import javax.sql.DataSource;
Publi class C3P0Utils
{
Private static DataSource ds = new ComboPooledDataSource();
Public static DataSource getDataSource()
{
Return ds;
}
}
然后写daoimpl层
QueryRunner qr = new QueryRunner(C3P0Utils.getDataSource());
下一个环节:国际化概念(了解)
步骤
1
创建一个消息资源包
比如:message_zh_CN.properties message_zh_HK.properties
里面大概是这个样的
key=\u5168\u5C40\u7684\u5C5E\u6027
jsp.login.username=\u7528\u6237\u540D
jsp.login.password=\u5BC6\u7801
jsp.login.denglu=\u767B\u9646
自己理解吧~
<!--[if !supportLists]-->2.<!--[endif]-->读取资源包中的内容
(在jsp页面上,head上面就行)
<%
Locale locale = request.getLocale();
ResourceBundle bundle = ResourceBundle.getBundle(“com.itherima.resources.message”,locale);
%>
<body>
<%=bundle.getString(“jsp.login.username”)%><input type=”text” name=”name”>
这个图有一个地方挺好玩的,就是拦截器那,在第一次拦截时候,已经运行了jsp页面了,只不过没显示东西。再次经过拦截器才把html页面运行出来。
写歌的人就该有伤悲,写首小调名字叫后悔。哪有唐人不懂 得陶醉,再上一层胭脂也不美。一声戛然而止的鞭炮,你说不要
跟不上了不写了,你说孤独是诗人应有的体会,