设为首页 收藏本站
查看: 1813|回复: 0

[经验分享] java+tomcat+struts2+mysql+myeclipse

[复制链接]

尚未签到

发表于 2015-8-8 08:41:28 | 显示全部楼层 |阅读模式
  MyEclipse配置Tomcat(图解) :http://shz2008bj.iteye.com/blog/166721%20
  MyEclipse开发web项目(jsp+Servlet):http://blog.sina.com.cn/s/blog_628cc2b70100jrpa.html%20
  MyEclipse开发web项目(jsp+Servlet):http://blog.sina.com.cn/s/blog_628cc2b70100p5ip.html
  struts2 框架下MyEclipse编写HelloWorld程序:http://blog.sina.com.cn/s/blog_628cc2b70100p7zg.html%20
  使用Struts2开发Java Web应用程序(目录) :http://blog.iyunv.com/struts2/article/details/1721752
  Maven起步-教你开始使用Maven:http://www.blogjava.net/i369/articles/86037.html
  MyEclipse连接MySQL的方法  :http://blog.163.com/w375257253@126/blog/static/17048785520105365416661/
  myeclipse安装在eclipse: http://jinguo.iteye.com/blog/378080
  Eclipse中添加MyEclipse插件:http://developer.iyunv.com/art/200906/130176.htm
  个人心得:
  调用http://xujiaxuan-pc:8080/struts2_demo/login.action 可以直接被拦截,并被转发到jsp界面
  成功例子:java案例教程的3章+myeclipse
  注意要点
  1.原来是配置文件struts.xml应该放在src下。同时web.xml放在webroot下
  2.eclipse或myeclipse调试没有source code 可能是每个类都继承自object有些没办法看到具体的初始化。继续f5就好了
  步骤:
  (1)myeclipse10
  myeclipse破解参考网址:http://blog.iyunv.com/ll136078/article/details/7197809
  myeclipse10版本的下载:
  http://downloads.myeclipseide.com/downloads/products/eworkbench/indigo/installers/myeclipse-10.0-offline-installer-windows.exe
  破解补丁以及下载地址:http://pan.baidu.com/share/link?shareid=165650&uk=1678594189
  注意(要在myeclipse中添加tomcat)
  (2)mysql 官方网址:http://www.mysql.com
  mysql驱动程序:http://pan.baidu.com/share/link?shareid=165653&uk=1678594189
  1.正常安装
  2.关于mysql的使用:直接点击MYSQL->MySQL Server 5.5->mysql 5.5 command line client
  3.输入密码 (默认的用户名为root) 或者
  开始,运行,cmd [ ,cd  mysql安装目录/bin ],  mysql -u userName -p Password
  mysql -h110.110.110.110 -uroot -pabcd123       // 远程登录 (登入前,服务器要先给客户端登入权限)
  (注:u与root可以不用加空格,其它也一样)
  4.驱动直接放到jre所在的目录 然后添加进classpath
  (3)struts2官方网址:http://struts.apache.org/download.cgi#struts2211
  书籍推荐:《java高级编程框架应用开发案例教程》(含code+ppt):
  http://pan.baidu.com/share/link?shareid=165674&uk=1678594189
  myeclipse->facets->选java版本修改为1.5或其他的>
  只需将需要struts2的项目的lib中添加stuts2中的lib下的相应jar包不要全部添加
  例子:
  文件结构
DSC0000.jpg
  mysql:


DSC0001.gif DSC0002.gif View Code


create database acesys;
use acesys;
create table Usr(
id int  primary key,
username nvarchar(50),
password nvarchar(50),
fullname nvarchar(50),
title nvarchar(50),
companyname nvarchar(50),
companyaddress nvarchar(50),
city nvarchar(50),
job nvarchar(50),
email nvarchar(50),
country nvarchar(50),
zip nvarchar(50),
tel nvarchar(50),
superuser nvarchar(50),
delsoft nvarchar(50),
note nvarchar(50))insert into Usr values (4,"1","1","1","1","1","1","1","1","1","1","1","1","p","1","1");
  struts.xml:


View Code







/registUsrWelcome.jsp
/registUsrWelcome.jsp
/adminWelcome.jsp
/login.jsp



  web.xml


View Code




Struts 2.0

struts2      
org.apache.struts2.dispatcher.FilterDispatcher


struts2
/*


index.jsp


  DBConn


View Code


package com.ascent.struts2.anli;
import java.sql.*;
public class DBConn {
public static Connection getConn()
{
Connection con=null;
try
{
//Class。forName("com.mysql.jdbc.Driver");
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/acesys";
String user="root";
String password="root";
con=DriverManager.getConnection(url,user,password);
}
catch(ClassNotFoundException e){
System.out.println("---找不到到驱动器");
}
catch (SQLException e)
{
System.out.println("获得数据库连接失败");
}
return con;
}
public static void dbClose(Connection con,Statement st,ResultSet rs){
try{
if(rs!=null)
{
rs.close();
rs=null;
}
if(st!=null){
st.close();
st=null;
}
if(con!=null)
{
con.close();
con=null;}
}catch(SQLException e){
e.printStackTrace();
}
}
}
  UsrDAO


View Code


package com.ascent.struts2.anli;
import java.util.ArrayList;
import java.util.List;
import com.ascent.struts2.po.Usr;
import java.sql.*;
public class UsrDAO {
private Connection con;
private PreparedStatement ps;
private ResultSet rs;
public Usr checkUsr(String username,String password){
Usr u=null;
String sql="select * from Usr";
try{
con=DBConn.getConn();
ps=con.prepareStatement(sql);
//ps.setString(1, username);
//ps.setString(2,password);
rs=ps.executeQuery();
if(rs.next())
{
u=new Usr();
u.setId(rs.getInt("id"));
u.setUsername(rs.getString("username"));
u.setEmail(rs.getString("email"));
u.setTel(rs.getString("tel"));
u.setSuperuser(rs.getString("superuser"));
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally{
DBConn.dbClose(con,ps,rs);
}
return u;
}
}
  Usr


View Code


package com.ascent.struts2.po;
/**
* Usr entity. @author MyEclipse Persistence Tools
*/
public class Usr implements java.io.Serializable {
// Fields
private int id;
private String username;
private String password;
private String fullname;
private String title;
private String companyname;
private String companyaddress;
private String city;
private String job;
private String tel;
private String email;
private String country;
private String zip;
private String superuser;
private String delsoft;
private String note;
// Constructors
/** default constructor */
public Usr() {
}
/** full constructor */
public Usr(String username, String password, String fullname, String title,
String companyname, String companyaddress, String city, String job,
String tel, String email, String country, String zip,
String superuser, String delsoft, String note) {
this.username = username;
this.password = password;
this.fullname = fullname;
this.title = title;
this.companyname = companyname;
this.companyaddress = companyaddress;
this.city = city;
this.job = job;
this.tel = tel;
this.email = email;
this.country = country;
this.zip = zip;
this.superuser = superuser;
this.delsoft = delsoft;
this.note = note;
}
// Property accessors
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFullname() {
return this.fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCompanyname() {
return this.companyname;
}
public void setCompanyname(String companyname) {
this.companyname = companyname;
}
public String getCompanyaddress() {
return this.companyaddress;
}
public void setCompanyaddress(String companyaddress) {
this.companyaddress = companyaddress;
}
public String getCity() {
return this.city;
}
public void setCity(String city) {
this.city = city;
}
public String getJob() {
return this.job;
}
public void setJob(String job) {
this.job = job;
}
public String getTel() {
return this.tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getCountry() {
return this.country;
}
public void setCountry(String country) {
this.country = country;
}
public String getZip() {
return this.zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getSuperuser() {
return this.superuser;
}
public void setSuperuser(String superuser) {
this.superuser = superuser;
}
public String getDelsoft() {
return this.delsoft;
}
public void setDelsoft(String delsoft) {
this.delsoft = delsoft;
}
public String getNote() {
return this.note;
}
public void setNote(String note) {
this.note = note;
}
}
  login.jsp


View Code








MY JSP 'LOGIN.JSP'STARTING PAGE


   





用户名:
密码:




  index.jsp


View Code








My JSP 'index.jsp' starting page


   





This is my JSP page.


  regisUsrWelcome.jsp


View Code








My JSP 'welcome.jsp' starting page


   





regisusr welcome


  adminWelcome.jsp


View Code








My JSP 'adminWelcome.jsp' starting page


   





admin welcome


  error.jsp


View Code








My JSP 'error.jsp' starting page


   





Struts2Demo
登陆失败!


  
运行结果:
DSC0003.jpg
  修改成下面的网址后显示为:
DSC0004.jpg
  输入用户名以及密码后:
DSC0005.jpg
  项目地址:http://pan.baidu.com/share/link?shareid=165680&uk=1678594189
  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-95305-1-1.html 上篇帖子: 用Eclipse,Axis和Tomcat构建Web Services 下篇帖子: Tomcat的webapps目录下新建的目录不能访问
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表