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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

idea+tomcat+struts2 搭建一个web实例

發布時間:2025/3/21 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 idea+tomcat+struts2 搭建一个web实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參考這個博客搭建:

Struts2快速入門與使用IntelliJ IDEA創建第一個web項目


需要注意幾點:

1)可能會遇到struts-default高亮變紅的情況,其實是沒有把struts-default.xml加入到Default File Set

解決辦法:


2)注意struts的版本,2.3有ng,2.5沒有



3)注意要進行部署操作


4)加載TOMCAT的時候要記得配置Deployment


5)注意各個文件的路徑,庫文件的加載


在這個實例中,我把namespace="/hello",也就是當執行HelloAction的sayHi這個ACTION方法之后,如果返回success狀態,那么又因為在上面配置的namespace=hello,頁面跳轉時尋找規則為web/namespace/xxx.jsp,也即是:

web/hello/sayHi.jsp

因此我們在瀏覽器輸入http://localhost:8080/hello/sayHi 訪問項目


通過瀏覽器訪問http://localhost:8080/hello/sayHi,控制臺會打印HelloAction中的hello world,同時頁面會跳轉到struts.xml中配置的sayHi.jsp頁面,頁面顯示之前寫的SayHi文字。


struts.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><package name="hello" namespace="/hello" extends="struts-default"><action name="sayHi" class="com.southstar.demo.HelloAction" method="sayHi"><result name="success">sayHi.jsp</result></action></package> </struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><display-name>Struts Blank</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> </web-app>

Action

package com.southstar.demo;public class HelloAction {public String sayHi() {System.out.println("hello world");return "success";} }

sayHi.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body> 沒魚,SB </body> </html>

至此,一個完整的簡單struts實例,創建完成!

?

總結

以上是生活随笔為你收集整理的idea+tomcat+struts2 搭建一个web实例的全部內容,希望文章能夠幫你解決所遇到的問題。

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