1. 程式人生 > >struts框架實現的jsp頁面的跳轉的頁面詳細講解---深入struts一下!

struts框架實現的jsp頁面的跳轉的頁面詳細講解---深入struts一下!

在詳細分解中,發現在之前的index.jsp頁面還有一部分忘記說了

在頁面頂端還要加上一個標籤語句,在html標籤和doctype的上面的加上:

<%@taglib uri="/struts-tags" prefix="s" %>

所以整個頁面就是這樣:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!-- 用於呼叫struts標籤 -->

<!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">
	-->
  </head>
  
  <body>
    	<s:form action="login2">
    	<!-- 建立跳轉表格 -->
        <s:textfield name="username"></s:textfield>
        <!-- 這裡是闖進文字框,name為文字框中輸入的變數 -->
    	<s:textfield name="password"></s:textfield>
    	<s:submit value="提交"></s:submit>
    	<!-- 這個是提交的按鈕,一點選就進行跳轉 -->
    </s:form>
  </body>
</html>
然後就是建立一個新的jsp頁面,內容不需要修改,以建立,內容就為:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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 'MyJsp.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>
    This is my JSP page. <br>
  </body>
</html>
然後就去建立連線兩個jsp頁面的java類:
import com.opensymphony.xwork2.ActionSupport;

public class ActionLogins extends ActionSupport {
	String username,password;
	//這裡是建立jsp頁面輸入的變數,提供引數的傳遞
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	//上面是建立變數的get/set方法來封裝變數

	public String execute() throws Exception {
		//這裡是建立執行方法,預設是execute方法,也可以寫其他方法,在配置檔案中修改method屬性就可以呼叫了
		return SUCCESS;
		//返回字串常量
	}
}
然後配置struts.xml配置檔案:
<?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" extends="struts-default">
	<!-- 這裡是struts呼叫的包,具體也沒有太明白,反正這格式就是這樣的 -->
       <action name="login2" class="actions.ActionLogins">
       <!-- 這裡是對action進行設定,action的名字和對應的類是什麼都可以看到,還有method屬性也可以設定 -->
           <result name="success">/MyJsp.jsp</result> 
           <!-- 這裡是返回的字串對應跳到的頁面是哪個,這裡是到MyJsp.jsp頁面 --> 
       </action>
   	</package>
</struts>    

然後執行就會出現index.jsp頁面的內容,點選提交就可以跳轉到MyJsp.jsp頁面了。

在MyJsp.jsp頁面的body標籤中加入

{$username}

這個語句,可以獲取index.jsp頁面中輸入的username的文字框中的值。不信的可以試試咯!

相關推薦

struts框架實現jsp頁面頁面詳細講解---深入struts一下

在詳細分解中,發現在之前的index.jsp頁面還有一部分忘記說了 在頁面頂端還要加上一個標籤語句,在html標籤和doctype的上面的加上: <%@taglib uri="/struts-tags" prefix="s" %> 所以整個頁面就是這樣: <

jsp request頁面和response頁面

例如: 有3個頁面p1.jsp , p2.jsp , p3.jsp ;  p1.jsp提交給p2.jsp , p2.jsp在轉發給p3.jsp  如果在p2用第一種方法發到到p3,由於是瀏覽器請求的是p2,請求的一些引數被封裝在request中,發給伺服器,伺服器用request.getRequestDisp

struts-config.xml裡代替頁面

之前也搞不懂,後來也是看了Struts的Example 才弄懂。 如: 要一個連線“產品”連結到products.do,而顯示的內容是products.jsp裡的內容,在連結過程中沒有任何的業務邏輯,那麼只要在struts-config.xml里加上這一句就好了: xml 程

jquery mobile如何實現滑動螢幕頁面

$("#detail_center").bind("swipeleft", function(e){$.mobile.changePage ('index.html', 'fade', false, false);});首先swipeleftapi如下:swipe(划動)

href 頁面頁面 參數

div str pan color href ati ref regexp ret $.getUrlParam = function (name) { var reg = new RegExp("(^|&)" + name + "=([

JSP與Servlet之後臺頁面單條刪除與多條刪除的頁面實現

.get func rac web nbsp pre resp har 做的 單條刪除頁面跳轉 1、首先打開JSP頁面,找到刪除 2、這個時候要把它改成servlet的URL,並決定要傳給後臺什麽數據,例如我需要傳一個待刪數據的ID id並不是什麽見不得

struts入門,實現頁面

struts的配置,相當簡單,我採用的是maven將struts依賴的包匯入到專案中。 第一步: ·在Eclipse下安裝MAVEN,具體教程就不詳細說了,百度安裝MAVEN。 ·然後新建maven專案 完成後,就有一個新的專案空間在左邊Package Explore

jsp頁面實現倒計時自動

在頁面上顯示倒計時 <script type="text/javascript"> function out(sec){ var v = document.getElementById("h1"); if(--sec>0){ se

js 按鈕實現頁面 jsp html

type=button      就單純是按鈕功能   type=submit      是傳送表單 但是對於從事WEB UI的人應該要注意到,使用submit來提高頁面易用性:使用submit後,頁面支援鍵盤enter鍵操作,而很多WEB軟體設計師,可能沒有注意到submi

AngularJS路由實現頁面

href vid 左邊欄 ref 按順序 -1 生活用品 func 為我 <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <titl

php中實現頁面的幾種方式

腳本 timeout location clas replace asc idt lee 實現 親測,not復制粘貼 PHP中實現頁面跳轉有一下幾種方式,看了幾個人寫的不是很條理,自己整理一下 在PHP腳本代碼中實現 <?php header("locati

Spring Security4.1.3實現攔截登錄後向登錄頁面方式(redirect或forward)返回被攔截界面

response href tools 當前 錯誤 界面 sets view 鏈接 一、看下內部原理 簡化後的認證過程分為7步: 用戶訪問網站,打開了一個鏈接(origin url)。 請求發送給服務器,服務器判斷用戶請求了受保護的資源。

ui li 形式的菜單 實現頁面

頁面跳轉 app /*跳轉*/ jumpEditRectificatBill:function(){ $("#getEquipLegerFrom li").each(function(){ //var jumpid=$(this).attr("id")

實現幾秒後頁面

member settime meid var else mem html class function /* 功能: 實現幾秒後跳轉頁面 */ window.onload=function(){ goTime(); } var goUrl="memb

html中提交表單並實現頁面處理返回值

html value put 提示 pan sdn type detail all <html> <head> <script type="text/javascript" src="h

<問題解決10>使用帶有框架頁面到登錄頁面時,登錄頁面只顯示在子框架中,未能鋪滿整個瀏覽器--解決方案如下:

頁面 tro color 過期 描述 例如 ren 方案 col 問題描述:     使用帶有框架的頁面跳轉到登錄頁面時,登錄頁面只顯示在子框架中,未能鋪滿整個瀏覽器,例如:     當登錄信息過期時,點擊左邊的菜單欄會讓登錄頁面顯示在右邊的框架中,而不能鋪滿整個瀏覽器  

spring boot框架學習9-spring boot的web開發(5)-錯誤解決及頁面

凱哥spring boot spring boot框架 本章節主要內容:通過前面的學習,我們了解並快速完成了spring boot第一個應用。spring boot企業級框架,那麽spring boot怎麽讀取靜態資源?如js文件夾,css文件以及png/jpg圖片呢?怎麽自定義消息轉換器呢?怎麽自定

【前臺】整個項目實現頁面,拋棄iframe

點擊事件 true charset req 做到 value images tro Language 即如下: 【想做到點擊nav側邊欄,僅替換右邊div中的內容,而不是跳轉到新的頁面,這樣的話,其實整個項目中就只有一個完整的頁面,其他的頁面均只寫<body>內

spring boot security 實現根據情況不同頁面功能

invalid static request config 隱藏 ctu gif cte send 在配置主類添加代碼 @Override protected void configure(HttpSecurity http) throws Except

用js實現頁面的幾種方式

head 註意 ont rem text pla http bsp cat 通過js或者html或者PHP等動態程序都可以方便的實現跳轉,這裏搜集了幾種頁面跳轉的方式js方式的頁面跳轉1.window.location.href方式 <script langua