一 Struts2 开发流程
生活随笔
收集整理的這篇文章主要介紹了
一 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的注冊配置
注意: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 开发流程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下运行Jmeter脚本
- 下一篇: locate 和 find