日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

一 Struts2 开发流程

發布時間:2025/3/15 编程问答 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一 Struts2 开发流程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SSH與SSM簡介
SSM:Spring+SpringMVC+Mybatis
SSH:Struts2+Hibernate+Spring
Struts2:是側重于控制層的框架
Hibernate:是一個ORM(Object Relation Mapping)的產品,專職于做DAO層
Spring:是一個項目的大管家或者是大容器。它負責各個層次的融合

為什么要用框架來開發項目?
1.簡化開發流程
2.標準化開發流程
3.增強項目的擴展性和維護性

Struts2的開發流程:
1.新建web項目,加入struts2的核心jar包

2.在項目中的web.xml中加入struts2的核心過濾器

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"><display-name>struts2_06</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.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list> </web-app>

3.在src目錄下創建一個struts.xml的配置文件

4.在src目錄下新建Action普通類,在類中寫一個public String execute() 返回一個字符串

package com.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{public String execute(){System.out.println("我的struts2第一個action");return "success";} }


5.在struts.xml中完成Action的注冊配置

<?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><package name="my" namespace="/" extends="struts-default"><action name="login" class="com.action.LoginAction"><result name="success">/jsp/success.jsp</result></action></package> </struts>

注意:name="login"是指action的訪問路徑
    <result name="success">/jsp/success.jsp</result>:是返回后的跳轉結果

?6.login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE html> <html> <head> <base href="<%=basePath%>"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body><form action="login">用戶名:<input name="username"><br>密碼:<input type="password" name="pwd"><br><input type="submit" value="提交"></form> </body> </html>

  點擊提交即可跳轉至success.jsp頁面?

轉載于:https://www.cnblogs.com/wlxslsb/p/10769568.html

總結

以上是生活随笔為你收集整理的一 Struts2 开发流程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。