本次学习的内容是struts通配符配置:
具体内容为:
一、准备工作
1.新建Web工程
2.添加struts:右键点击工程名选择My Eclipse-->点击add struts..-->添加struts2.1
二、编写程序
1.建com.bjsxt.struts2.action包(名字可自拟),并在其中编写StudentAction和TeacherAction。
附Student代码:
package com.bjsxt.struts2.action;
import com.opensymphony.xwork2.ActionSupport;
public class StudentAction extends ActionSupport { public String add() { return SUCCESS; }
public String delete() { return SUCCESS; }}
2.编写jsp代码:写出Studentadd、Teacheradd、Studentdelete、Teacheradddelete四个代码,并修改index.jap代码。
三、注意事项
1.使用通配符,将配置量降到最低
2.不过,一定要遵守"约定优于配置"的原则
3.在jsp页面中必须有<%@ taglib uri="/struts-tags" prefix="s" %>
4.web.xml中需要修改部分代码:
如:<filter-mapping>
<filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
5.struts.xml也需要写出部分代码:
如:<?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.devMode" value="true" /> <package name="actions" extends="struts-default" namespace="/actions"> <action name="Student*" class="com.bjsxt.struts2.action.StudentAction" method="{1}"> <result>/Student{1}_success.jsp</result> </action> <action name="*_*" class="com.bjsxt.struts2.action.{1}Action" method="{2}"> <result>/{1}_{2}_success.jsp</result> <!-- {0}_success.jsp --> </action> </package></struts>
心得与体会:多学习网上视频,要学会自主学习,做完代码后应再观看一遍视频,发现错误修改错误,这样才能在以后取得更好的成绩。还有代码一定要多学多写多练。
转载于:https://www.cnblogs.com/zhang-miaomiao/p/5354802.html
相关资源:JAVA上百实例源码以及开源项目