Ubuntu+eclipse+Struts2.x开发平台搭建方法
来源:互联网 发布:速卖通数据分析 编辑:程序博客网 时间:2024/04/30 03:06
网上找的教程都不完美,也许我这个教程也不完美,主要是包导入不完整,但是可以教大家如何做到完美。
1、添加jar包
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.16.3.jar
xwork-core-2.3.16.3.jar
2、在web.xml配置文件中配置过滤器
<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>
3、创建一个action
package com.skywo.action;public class LoginAction {// servlet api xxxpublic String execute() throws Exception{if(username != null && username.equals("skywo")){return "success";}else{return "failure";}}/*public String login() throws Exception{if(username != null && username.equals("skywo")){return "success";}else{return "failure";}}*/private String username;private String password;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}4、配置action在struts.xml配置文件中,struts.xml放到src/下面。
<?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> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="example" namespace="/" extends="struts-default"> <action name="login" class="com.skywo.action.LoginAction"> <result name="success">/Success.jsp</result> <result name="failure">/Failure.jsp</result> </action> </package></struts>
5、JSP调用
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><% String path= request.getContextPath();%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Insert title here</title></head><body><form name="f1" action="<%=path %>/login.action" method="post"><table border="0"><tr><td>Username: </td><td><input type="text" name="username"></td></tr><tr><td>Password: </td><td><input type="password" name="password"></td></tr><tr><td colspan="2" align="center"><input type="submit" value="Login"></td></tr></table></form></body></html>
在这里要注意的是,启动tomcat的时候出现的错误不要无视,之前我就是犯了这个错误才导致了很多麻烦,一般都提示缺少包,添加对应的包即可~
0 0
- Ubuntu+eclipse+Struts2.x开发平台搭建方法
- 搭建开发平台Eclipse
- 搭建开发平台Eclipse
- ubuntu下使用eclipse搭建c/c++开发平台
- 搭建开发平台—Eclipse
- 搭建Eclipse+Qt开发平台
- Eclipse搭建hadoop开发平台
- ubuntu搭建java开发平台
- 【Struts2】eclipse 下搭建 Struts2 开发环境
- Ubuntu下Eclipse C++开发环境搭建方法
- Ubuntu 10.04 Eclipse C/C++平台搭建
- Ubuntu 10.04 Eclipse C/C++平台搭建
- Ubuntu 10.04 Eclipse C/C++平台搭建
- Ubuntu 10.04 Eclipse C/C++平台搭建
- Ubuntu+QT+VTK+Eclipse&QtCreator开发平台的搭建(一行命令即可)
- Eclipse下搭建Struts2开发环境
- 在eclipse开发环境中搭建struts2
- 在eclipse中搭建struts2开发环境
- 判断输入值与随机数是否相同
- java的IO处理
- Saiku去掉登录模块(默认不跳转登陆页面而是跳转主页面)
- java自带线程池和队列详细讲解
- pp6.7 stars/a
- Ubuntu+eclipse+Struts2.x开发平台搭建方法
- 并发编程之Operation Queue和GCD
- c18
- 收藏的一个linux下proxy实现的源码
- Galaxy Tab S 8.4/10.5 Root 教程 + Recovery
- eclipse中文字体大小修改,让中英文字体协调
- sql合并字段
- RHEL 6.4 安装 cx_Oracle
- Ubuntu 14.04 安装chrome 38.0