jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <h3>演示Servlet的API的第一种方式(完全解耦合的方式)</h3> <form action="${ pageContext.request.contextPath }/demo1Action.action" method="post"> 姓名:<input type="text" name="username" /><br /> 密码:<input type="password" name="password" /><br /> <input type="submit" value="注册" /> </form> </body> </html>
java:
package com.itheima.demo1; /** * 完全解耦合的方式 ,使用Servlet的API */ import com.opensymphony.xwork2.ActionSupport; //注意这里的继承 public class Demo1Action extends ActionSupport { private static final long serialVersionUID = 1L; @Override //这个是重写默认的方法 public String execute() throws Exception { System.out.println("代表页面跳转"); return super.execute(); } }
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- name属性是自己设置的 --> <package name="demo1" extends="struts-default" namespace="/"> <!-- 完全解耦合的方式配置 --> <action name="demo1Action" class="com.itheima.demo1.Demo1Action"></action> </package> </struts>