S2SH整合以及图片上传(5)之struts2的搭建

    经过前面一番操作之后,我们已经把spring和hibernate整合搭建完毕。

    接下来,我们对最后一个框架struts2进行搭建。

    详细步骤如下。

    第一步,我们依然导入相关的jar包到新建的web项目的/TestUpload/WebRoot/WEB-INF/lib目录中

    

    第二步,我们在项目的src目录下新建struts2的核心配置文件struts.xml:

    

     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>


    <!-- 开启动态方法调用 -->
    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

     <!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 -->
    <constant name="struts.i18n.encoding" value="UTF-8"></constant>

    <!-- 开发模式下使用,这样可以打印出更详细的错误信息 -->
    <constant name="struts.devMode" value="true" />

    <!-- 允许静态方法调用 -->
    <constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>

    <!-- 设置文件最大上传的容量大小,这里设置的是10M -->
    <constant name="struts.multipart.maxSize" value="10701096" />

    <!-- Struts2和Spring集成的一个比较关键的配置,与Spring集成时,指定由Spring负责action对象的创建    -->
    <constant name="struts.objectFactory" value="spring" />
	

</struts>


    第三步,我们需要在项目的web.xml中配置struts:

   ( web.xml的位置:TestUpload/WebRoot/WEB-INF/web.xml)

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
	<display-name></display-name>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>

	<!-- 配置struts2 -->
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
		<init-param>
			<param-name>struts.i18n.encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

</web-app>

    第四步,我们先创建需要的jsp页面index.jsp,add.jsp,operate_success.jsp:

    index.jsp内容如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Person Page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
   	<h2>S2SH整合以及图片上传</h2>
   	<a href="${pageContext.request.contextPath}/add.jsp">添加人员</a>
   	<hr />
  </body>
</html>

    add.jsp内容如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Person Operate Page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
   	<h2>S2SH整合以及图片上传</h2>
   	<h2>添加人员</h2>
   	<s:form action="person!add" namespace="/person" method="post" enctype="multipart/form-data">
		<table>
			<tr>
				<td><input type="submit" value="上传" /></td>
			</tr>
		</table>
	</s:form>
   	
  </body>
</html>

    operate_success.jsp内容如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Operate Success Page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
   	<h2>S2SH整合以及图片上传</h2>
   	<h2>操作成功</h2>
   	<a href="${pageContext.request.contextPath}/index.jsp">返回主页</a>
  </body>
</html>

    第五步,我们在项目的src目下新建一个包,用来存储action:

    

    PersonAction内容如下:

package com.ssh.action;

import com.opensymphony.xwork2.ActionSupport;

public class PersonAction extends ActionSupport{

	private static final long serialVersionUID = 1L;

	public String add(){
		return SUCCESS;
	}
}

    第六步,我们配置struts的核心配置文件struts.xml,添加如下内容:

    <package name="person" namespace="/person" extends="struts-default" >

       <action name="person" class="personAction">
       		<result name="success">/operate_success.jsp</result>
       </action>
    </package>

    第七步,由于我们是S2SH整合开发,所以struts中的action将交由spring来接管,即在applicationContext.xml中配置如下内容:

    

    代码如下:

<!-- 配置action的bean -->
<bean id="personAction" class="com.ssh.action.PersonAction" scope="prototype" />

    第八步,我们需要在web.xml中配置applicationContext.xml的启动:   

	<!-- 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:applicationContext.xml</param-value>
	</context-param>
	<!-- 对Spring容器进行实例化 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

    第九步,测试struts框架是否搭建成功:

    控制台显示成功:



    在网页中显示成功:

    

    

    

    至此,struts框架搭建完毕!

    S2SH整合以及图片上传(6)之图片上传

Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值