初涉配置struts

来源:互联网 发布:淘宝分销和代销的区别 编辑:程序博客网 时间:2024/06/05 11:23

暂时使用这些基本jar包


如此结构

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_3_1.xsd" id="WebApp_ID" version="3.1"><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.filter.StrutsPrepareAndExecuteFilter</filter-class>//这里主要2.5以后少了.ng包</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.0//EN"    "http://struts.apache.org/dtds/struts-2.0.dtd">    <struts>        <package name="default" namespace="/" extends="struts-default">        <!-- name action的名字,访问时使用helloworld.action访问,class:实现类 -->        <action name="index" >            <!-- 结果集,即action中SUCCESS返回的视图 -->            <result>            /index.jsp            </result>        </action>        </package>    </struts>
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>配置好基本的struts2环境</h1> </body> </html> 
run index.jsp

在浏览器URL: http://localhost:8080/struts01/index.action

成功跳转

出现问题应该都是web.xml或struts.xml问题,好像无其他配置关系



原创粉丝点击