struts-2小練習

index.jsp

<%@ page language="java" import="java.util.*" import="pack1.filter1"  pageEncoding="ISO-8859-1"%>

<%@ 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 'index.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">
    -->
<script language="javascript">
function fun(){
<%
out.print("fdasf");
%>
}
</script>
  </head>

  <body>


    This is my JSP page. <br>

    <a href="first!jia">tianjiao</a>
    <a href="first!geng">gengxin</a>
    </form>
    <font color="red"> 
        <s:property value="info"/>
    </font>


  </body>
</html>

配置下struts.xml

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
    "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
    <!-- 聲明包 -->
    <package name="myPackage" extends="struts-default">
        <!-- 定義action -->
        <action name="first" class="pack1.filter1">
            <!-- 定義處理成功後的映射頁面 -->

            <result name="jia">/user.jsp</result>
            <result name="geng">/geng1.jsp</result>
        </action>

    </package>
</struts>

Note:
href=”<%=basePath%>”>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章