根据不同的输入值实现页面跳转.structs

来源:互联网 发布:在线浏览器代理软件 编辑:程序博客网 时间:2024/04/30 09:35

================================================================

package com.structs;

import com.opensymphony.xwork2.Action;

public class SkipPageAction implements Action {

 String input;//接收输入
 String type;//类型

 @Override
 public String execute() throws Exception {
  return null;
 }

 public String getInput() {
  return input;
 }

 public String getType() {
  return type;
 }

 public void setInput(String input) {
  this.input = input;
 }

 public void setType(String type) {
  this.type = type;
 }

 public String choose() {

  if (input.equals("in")) {
   type = "/pages/login.jsp";
  } else if (input.equals("out")) {
   type = "/pages/logout.jsp";
  } else {
   type = "/pages/error.jsp";
  }
  return "mychoose";
 }

}

======================structs配置文件==========================

<?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>
 <constant name="struts.devMode" value="false" />
 <constant name="struts.enable.DynamicMethodInvocation" value="false" />

 <package name="test" namespace="/" extends="struts-default">
  <action name="loginss" class="com.structs.SkipPageAction"
   method="choose">
   <result name="mychoose" type="redirect">${type}</result>
  </action>
 </package>
 <!--package name:包名 ,action处理表单响应(name="任意名称",method="类的方法名称");result name:返回字符串的名称-->

</struts>

=================form表单获取输入数据========================
<body>
 <div align="center">
  <form action="loginss">
   <input type="text" name="input"> <input type="submit"
    value="提交">
  </form>
 </div>
</body>

=====================xml配置============================


 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 <display-name></display-name>

 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

 

原创粉丝点击