当前位置:编程学习 > JS >>

struts2 入门实例 相关代码备份

package action;
 
import com.opensymphony.xwork2.ActionSupport;
 
public  class FirstAction extends ActionSupport
{
    /**
  *
  */
 private static final long serialVersionUID = 1L;
 private int operand1;
    private int operand2;
 
    public String execute() throws Exception
    {
        if (getSum() >= 0)  // 如果代码数和是非负整数,跳到positive.jsp页面
        {
            return "positive";
        }
        else  // 如果代码数和是负整数,跳到negative.jsp页面
        {
            return "negative";
        }
    }
 
    public int getOperand1()
    {
        return operand1;
    }
 
    public void setOperand1(int operand1)
    {
        System.out.println(operand1);
          this.operand1 = operand1;
    }
 
    public int getOperand2()
    {
        return operand2;
    } 
    public void setOperand2(int operand2)
    {
        System.out.println(operand2);
        this.operand2 = operand2;
    }
    public int getSum()
    {
        return operand1 + operand2;  // 计算两个整数的代码数和
    }
}


 

<?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>
<package name="default" namespace="/" extends="struts-default">

          <action name="sum" class="action.FirstAction">
              <result name="positive">/positive.jsp</result>
              <result name="negative">/negative.jsp</result>
          </action>
      </package>

</struts>   


 

 

<?xml version="1.0" encoding="UTF-8"?>
<beans
 xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:p="http://www.springframework.org/schema/p"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


</beans>

 

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 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_2_5.xsd">
 
 
  <display-name></display-name>
 
  
   
  <welcome-file-list>
    <welcome-file>sum.jsp</welcome-file>
  </welcome-file-list>
 
 
  <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>
 
 
 
  </web-app>


 

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
  <%@ taglib prefix="s" uri="/struts-tags" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'negative.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

  </head>
 
  <body>
      代数和为负整数<h1><s:property value="sum" /></h1>
     
    </body>

</html>


 

 

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
  <%@ taglib prefix="s" uri="/struts-tags" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'positive.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">补充:Web开发 , Jsp ,

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,