亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

是按最簡單的例子在寫的,但總是404.。

本人小白,剛入struts2.之前用的2.5.17版,但是沒有blank。war。。所以回裝了2.3版本。但是實驗最簡單的action例子總是失敗。代碼如下:web.xml

<?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_4_0.xsd" id="WebApp_ID" version="4.0">
?<display-name>HelloWorld</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- 配置核心攔截器 -->
<filter>
??? <!-- Filter的名字 -->
??? <filter-name>struts2</filter-name>
??? <!-- Filter的實現類 struts2.5以前可能有所不同 -->
??? <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>???
<filter-mapping>
??? <filter-name>struts2</filter-name>
??? <!-- 攔截所有的url -->
??? <url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

struts.xml

<?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="default" namespace="/" extends="struts-default" strict-method-invocation="false">
??????? <!-- name action的名字,訪問時使用helloworld.action訪問,class:實現類 -->
??????? <action name="helloworld" class="cn.xhcoding.action.HelloWorldAction">
??????????? <!-- 結果集,即action中SUCCESS返回的視圖 -->
??????????? <result>/result.jsp</result>
??????? </action>

??????? </package>
??? </struts>


action類

package cn.xhcoding.action;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldAction extends ActionSupport {
?@Override
??? public String execute() throws Exception {
??????? System.out.println("正在執行的Action");
??????? // 返回視圖 SUCCESS,這是框架定義
??????? return SUCCESS;
??? }
}

result.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Action Result</title>
</head>
<body>
<h1>恭喜成功配置好基本的struts2環境</h1>
<h2>Hello World, I am Successful</h2>
</body>
</html>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Action Result</title>
</head>
<body>
<h1>index</h1>

</body>
</html>

.可以顯示

https://img1.sycdn.imooc.com//5b9cc6630001fb6408360520.jpg

https://img1.sycdn.imooc.com//5b9cc6640001a13a08160453.jpg


正在回答

1 回答

訪問的網址有問題吧?

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

是按最簡單的例子在寫的,但總是404.。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號