SSH2整合+分页+ajax+js校验用户名

1 action:
FriendAction
package com.ipanel.action;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.ipanel.entity.Friend;
import com.ipanel.service.FriendService;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class FriendAction extends ActionSupport {
private Friend friend;
private FriendService friendService;
private String phone;
private String name;
private String sex;

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public Friend getFriend() {
return friend;
}

public void setFriend(Friend friend) {
this.friend = friend;
}

public FriendService getFriendService() {
return friendService;
}

public void setFriendService(FriendService friendService) {
this.friendService = friendService;
}

// 删除好友
public String delete() {
friend = this.friendService.findByName(friend.getName());

this.friendService.delete(friend);

return "deletefriend";
}
// 添加好友
public String save() {
System.out.println(name+";"+phone+";"+sex);
if(name==null||"".equals(name.trim())){
this.addFieldError(getName(), "用户名不能为空");
}else{
friend = new Friend();
friend.setName(name);
friend.setPhone(Integer.parseInt(phone));
friend.setSex(sex);
this.friendService.save(friend);
}

return "save";
}
// // 查询好友
// public String find(Friend friend){
// friend=this.friendService.findByName(name);
// return "findfriend";
// }
// // 修改好友
// public String update(Friend friend){
// friend=this.friendService.findByName(name);
// friend.setName(name);
// friend.setPhone(phone);
// friend.setSex(sex);
// this.friendService.save(friend);
// return "save";
// }
//验证用户名
public String checkUserName() throws IOException{
HttpServletResponse response = ServletActionContext.getResponse();
PrintWriter out = response.getWriter();
System.out.println("jsgfs");
friend=friendService.findByName(name);
System.out.println(name);
if(friend==null)
{
out.print(1);
}
else
{
out.print(0);
}
return null;
}
@Override
public String execute() throws Exception {
return "input";
}
}
PcookAction
package com.ipanel.action;
import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.ipanel.entity.Pcook;
import com.ipanel.service.PcookService;
import com.opensymphony.xwork2.ActionSupport;
public class PcookAction extends ActionSupport {
private Pcook pcook;
private PcookService pcookService;
private String name;
private String percent;

private List<Pcook> list;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPercent() {
return percent;
}
public void setPercent(String percent) {
this.percent = percent;
}
//public String checkFood() throws IOException{
// HttpServletResponse response = ServletActionContext.getResponse();
// PrintWriter out=response.getWriter();
// List pcook=new ArrayList();
// pcook=pcookService.findPcookByName(name);
// if(pcook==null){
// out.print(0);
// }else{
// out.print(1);
// }
//
// return null;
//}
public String findAll()throws UnsupportedEncodingException{
HttpServletRequest request = ServletActionContext.getRequest();
String curpage = request.getParameter("curpage"); // 当前页
String pagesize = "10"; // 页大小
list = pcookService.queryByPage(curpage, pagesize, request);
return "allfind";
}
public String findPcookByName() {
HttpServletRequest request = ServletActionContext.getRequest();
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
list=this.pcookService.findPcookByName(name);
System.out.println(list);
return "ByName";
}
public Pcook getPcook() {
return pcook;
}
public void setPcook(Pcook pcook) {
this.pcook = pcook;
}
public PcookService getPcookService() {
return pcookService;
}
public void setPcookService(PcookService pcookService) {
this.pcookService = pcookService;
}
public List<Pcook> getList() {
return list;
}
public void setList(List<Pcook> list) {
this.list = list;
}

}
dao
package com.ipanel.dao;

import java.util.List;
import com.ipanel.entity.Friend;


public interface FriendDao {
public void saveFriend(Friend friend);
public void deleteFriend(Friend friend);
public Friend findFriendByName(String Name);
public List<Friend> findAllFriend();
public void updateFriend(Friend friend);
}

package com.ipanel.dao;

import java.util.List;
import com.ipanel.entity.Pcook;

public interface PcookDao {
public void savePcook(Pcook pcook);
public void deletePcook(Pcook pcook);
public List<Pcook> findPcookByName(String Name);
public List<Pcook> findAllPcook();
public void updatePcook(Pcook pcook);
/**
* 分页查询
* @param curpage
* @param pagesize
* @return
* @throws Exception
*/
public List queryByPage(int curpage, int pagesize);
/**
* 得到总记录数
* @return
*/
public int queryCount();
}

dao.impl
package com.ipanel.dao.impl;

import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ipanel.dao.FriendDao;
import com.ipanel.entity.Friend;


public class FriendDaoImpl extends HibernateDaoSupport implements FriendDao {

public void deleteFriend(Friend friend) {
this.getHibernateTemplate().delete(friend);

}

@SuppressWarnings("unchecked")
public List<Friend> findAllFriend() {
String hql="from friend order by friend.friend_id desc";
List<Friend> list=this.getHibernateTemplate().find(hql);
return list;
}

@SuppressWarnings("unchecked")
public Friend findFriendByName(final String name) {
final String sql = "from Friend fre where fre.name=?";
List<Friend> list = this.getHibernateTemplate().executeFind(
new HibernateCallback()
{
public Object doInHibernate(Session s)
throws HibernateException, SQLException
{
Query query = s.createQuery(sql);
query.setString(0, name);
List list = query.list();
return list;
}
});
if (null != list && !list.isEmpty())
{
return list.get(0);
}
return null;
}

public void saveFriend(Friend friend) {

this.getHibernateTemplate().save(friend);

}

public void updateFriend(Friend friend) {
this.getHibernateTemplate().update(friend);

}





}

package com.ipanel.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ipanel.dao.PcookDao;
import com.ipanel.entity.Friend;
import com.ipanel.entity.Pcook;

public class PcookDaoImpl extends HibernateDaoSupport implements PcookDao {

public void deletePcook(Pcook pcook) {
// TODO Auto-generated method stub

}

public List<Pcook> findAllPcook() {
final String sql="from Pcook";
List<Pcook> list=this.getHibernateTemplate().find(sql);
return list;
}

@SuppressWarnings("unchecked")
public List<Pcook> findPcookByName(String name) {
String sql = "from Pcook fre where 1=1";
if (null != name && !"".equals(name))
{
sql += " and fre.name like '%" + name + "%'" ;
}
final String hql = sql;
List<Pcook> list = this.getHibernateTemplate().executeFind(
new HibernateCallback()
{
public Object doInHibernate(Session s)
throws HibernateException, SQLException
{
Query query = s.createQuery(hql);
// query.setString(0,"%"+Name+"%");
List list = query.list();
return list;
}
});
return list;

}

public void savePcook(Pcook pcook) {
// TODO Auto-generated method stub

}

public void updatePcook(Pcook pcook) {
// TODO Auto-generated method stub

}

/**
* 分页查询
* @param curpage
* @param pagesize
* @return
* @throws Exception
*/
public List queryByPage(int curpage, int pagesize) {
List list = null;
try {
String hql = "from Pcook";
Query query = this.getSession().createQuery(hql);
query.setFirstResult((curpage - 1) * pagesize);
query.setMaxResults(pagesize);
list = query.list();
return list;
} catch (Exception e) {
e.printStackTrace();
}
return list;
}

/**
* 得到总记录数
* @return
*/
public int queryCount() {
String hql = "from Pcook";
List<Pcook> list = this.getHibernateTemplate().find(hql);
return list.size();
}

}

entity
package com.ipanel.entity;

import java.util.Date;

public class Friend {
private int id;
private String name;
private int age;
private String sex;
private int role_id;
private double weight;
private double beam;
private double waistl;
private double chestm;
private Date birthday;
private double high;
private int phone;

public Friend() {

}

public Friend(int id, String name, int age, String sex, int roleId,
double weight, double beam, double waistl, double chestm,
Date birthday, double high,int phone) {
this.id = id;
this.name = name;
this.age = age;
this.sex = sex;
role_id = roleId;
this.weight = weight;
this.beam = beam;
this.waistl = waistl;
this.chestm = chestm;
this.birthday = birthday;
this.high = high;
this.phone = phone;
}
public int getPhone() {
return phone;
}

public void setPhone(int phone) {
this.phone = phone;
}

public String getSex() {
return sex;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String isSex() {
return sex;
}


public void setSex(String sex) {
this.sex = sex;
}

public int getRole_id() {
return role_id;
}

public void setRole_id(int roleId) {
role_id = roleId;
}

public double getWeight() {
return weight;
}

public void setWeight(double weight) {
this.weight = weight;
}

public double getBeam() {
return beam;
}

public void setBeam(double beam) {
this.beam = beam;
}

public double getWaistl() {
return waistl;
}

public void setWaistl(double waistl) {
this.waistl = waistl;
}

public double getChestm() {
return chestm;
}

public void setChestm(double chestm) {
this.chestm = chestm;
}

public Date getBirthday() {
return birthday;
}

public void setBirthday(Date birthday) {
this.birthday = birthday;
}

public double getHigh() {
return high;
}

public void setHigh(double high) {
this.high = high;
}

@Override
public String toString(){
return this.name+this.sex+this.phone;
}
}

package com.ipanel.entity;

public class Pcook {
private int id;
private String name;
private String percent;

private String picture_path;

public Pcook() {

}

public Pcook(int id, String name, String percent,String picture_path) {
this.id = id;
this.name = name;
this.percent = percent;
this.picture_path = picture_path;
}

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPercent() {
return percent;
}
public void setPercent(String percent) {
this.percent = percent;
}

public String getPicture_path() {
return picture_path;
}

public void setPicture_path(String picturePath) {
picture_path = picturePath;
}


}

entity.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="entity.Friend">
<class name="com.ipanel.entity.Friend" table="friend">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="name" length="15" />
</property>
<property name="age" type="java.lang.Integer">
<column name="age" length="20" />
</property>
<property name="sex" type="java.lang.String">
<column name="sex" length="15"/>
</property>
<property name="role_id" type="java.lang.Integer">
<column name="role_id" length="20" />
</property>
<property name="weight" type="java.lang.Double">
<column name="weight" length="20" />
</property>
<property name="beam" type="java.lang.Double">
<column name="beam" length="20" />
</property>
<property name="waistl" type="java.lang.Double">
<column name="waistl" length="20" />
</property>
<property name="chestm" type="java.lang.Double">
<column name="chestm" length="20" />
</property>
<property name="birthday" type="java.sql.Date">
<column name="birthday" length="20" />
</property>
<property name="high" type="java.lang.Double">
<column name="high" length="20" />
</property>
<property name="phone" type="java.lang.Integer">
<column name="phone" length="255" />
</property>
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="entity.Friend">
<class name="com.ipanel.entity.Pcook" table="pcook">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="name" length="45" />
</property>
<property name="percent" type="java.lang.String">
<column name="percent" length="75" />
</property>
<property name="picture_path" type="java.lang.String">
<column name="picture_path" length="75" />
</property>
</class>
</hibernate-mapping>

service
package com.ipanel.service;

import java.util.List;

import com.ipanel.entity.Friend;


public interface FriendService {
public void save(Friend friend);
public void update(Friend friend);
public void delete(Friend friend);
public List<Friend>findAll();
public Friend findByName(String name);
}

package com.ipanel.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.ipanel.entity.Pcook;


public interface PcookService {
public void save(PcookService pcook);
public void update(PcookService pcook);
public void delete(PcookService pcook);
public List<Pcook>findAll();
public List<Pcook> findPcookByName(String Name);
/**
* 分页查询
* @param curpage
* @param pagesize
* @return
* @throws Exception
*/
public List queryByPage(String curpage, String pagesize, HttpServletRequest request);
}

service.impl
package com.ipanel.service.imp;


import java.util.List;

import com.ipanel.dao.FriendDao;
import com.ipanel.entity.Friend;
import com.ipanel.service.FriendService;


public class FriendServiceImpl implements FriendService {
private FriendDao friendDao;

public FriendDao getFriendDao() {
return friendDao;
}

public void setFriendDao(FriendDao friendDao) {
this.friendDao = friendDao;
}

public void delete(Friend friend) {
this.friendDao.deleteFriend(friend);

}

public List<Friend> findAll() {

return this.friendDao.findAllFriend();
}

public Friend findByName(String name) {

return this.friendDao.findFriendByName(name);
}

public void save(Friend friend) {
this.friendDao.saveFriend(friend);

}

public void update(Friend friend) {
this.friendDao.updateFriend(friend);

}
}

package com.ipanel.service.imp;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.ipanel.dao.PcookDao;
import com.ipanel.entity.Pcook;
import com.ipanel.service.PcookService;

public class PcookServiceImpl implements PcookService {
private PcookDao pcookDao;

public PcookDao getPcookDao() {
return pcookDao;
}

public void setPcookDao(PcookDao pcookDao) {
this.pcookDao = pcookDao;
}

public void delete(PcookService pcook) {
// TODO Auto-generated method stub

}

public List<Pcook> findAll() {

return this.pcookDao.findAllPcook();
}

public List<Pcook> findPcookByName(String Name) {

return this.pcookDao.findPcookByName(Name);
}

public void save(PcookService pcook) {
// TODO Auto-generated method stub

}

public void update(PcookService pcook) {
// TODO Auto-generated method stub

}

/**
* 得到总记录数
* @return
*/
private int queryCount() {
return this.pcookDao.queryCount();
}

/**
* 分页查询
* @param curpage
* @param pagesize
* @return
* @throws Exception
*/
public List queryByPage(String curpage, String pagesize, HttpServletRequest request) {
if("".equals(pagesize) || null == pagesize)
{
pagesize= "9";
}
if("".equals(curpage) || null == curpage)
{
curpage= "1";
}
int counts = this.queryCount();
int size = 9;

int cur = 1;
try {
size = new Integer(pagesize);
cur = new Integer(curpage);
} catch (NumberFormatException e) {
size=10;
cur=1;
}
int pages = 1;
if(counts > size) {
if(counts % size == 0) {
pages = counts / size;
} else {
pages = counts / size + 1;
}
}
if(cur < 1) {
cur = 1;
}
if(cur > pages) {
cur = pages;
}
request.setAttribute("counts", counts);
request.setAttribute("pages", pages);
request.setAttribute("curpage", cur);
request.setAttribute("pagesize", pagesize);
return this.pcookDao.queryByPage(Integer.parseInt(curpage), Integer.parseInt(pagesize));
}


}

配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/health" />
<property name="username" value="root" />
<property name="password" value="ipanel" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value> com/ipanel/entity/Friend.hbm.xml</value>
<value> com/ipanel/entity/Pcook.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
</value>
</property>
</bean>

<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 个性配餐 -->
<bean id="pcookAction" class="com.ipanel.action.PcookAction">
<property name="pcookService" ref="pcookService"></property>
</bean>
<bean id="pcookDao" class="com.ipanel.dao.impl.PcookDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="pcookService" class="com.ipanel.service.imp.PcookServiceImpl">
<property name="pcookDao" ref="pcookDao"></property>
</bean>

<!-- 好友添加 -->
<bean id="friendAction" class="com.ipanel.action.FriendAction">
<property name="friendService" ref="friendService"></property>
</bean>
<bean id="friendDao" class="com.ipanel.dao.impl.FriendDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>

</bean>
<bean id="friendService" class="com.ipanel.service.imp.FriendServiceImpl">
<property name="friendDao" ref="friendDao"></property>
</bean>
</beans>

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="friendAction" extends="struts-default" >
<action name="friendaction" class="com.ipanel.action.FriendAction">
<result name="save">/page/friend.jsp</result>
<result name="input">/laowang/hehe.jsp</result>
<result name="findfriend">/page/hehe.jsp</result>
<result name="checkFail">/page/friend.jsp</result>
<result name="checkSuccess">/page/friend.jsp</result>
</action>
</package>
<!-- 个性配餐 -->
<package name="pcookAction" extends="struts-default">
<action name="pcookAction" class="com.ipanel.action.PcookAction">
<result name="allfind" >/index.jsp</result>
<result name="checkFail">/index.jsp</result>
<result name="checkSuccess">/index.jsp</result>
</action>

</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>


<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

page/jsp
<%@ page language="java" 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>
<script type="text/javascript">

//声明XMLHttpRequest对象
var xmlHttp;
//检测用户名是否存在
function CheckName()
{
createXMLHTTP();//创建XMLHttpRequest对象
var name=document.getElementById("name");
var name = name.value;
var url = "<%=path%>/friend/friendaction!checkUserName?name=" + name;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=checkUserName;//修改下面的回调函数,回调函数主要处理后台返回的数据,回调函数的参数就是后台返回的数据。
xmlHttp.send(null);
}
//生成xmlhttp对象
function createXMLHTTP()
{
if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();//mozilla浏览器
}
else if(window.ActiveXObject)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");//IE老版本
}
catch(e)
{}
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
}
catch(e)
{}
if(!xmlHttp)
{
window.alert("不能创建XMLHttpRequest对象实例!");
return false;
}
}
}

//执行检测用户名回调函数
function checkUserName()
{
if(xmlHttp.readyState==4)//判断对象状态
{
if(xmlHttp.status==200)
{
var repResult = xmlHttp.responseText;
if ("0" == repResult)
{
document.getElementById("checkUser1111").innerHTML = "你的名字重复了。。。。";
}
}
}
}
function dosave() {
var reg = /^[A-Za-z_]+[0-9]*$/;
name = document.getElementById("name").value;
if (!reg.test(name)||name.length<1||name.length>20) {
document.getElementById("checkUserDiv").style.display = "block";
return false;
} else {
document.getElementById("checkUserDiv").style.display = "none";
}
var phone = document.getElementById("phone");
if (phone == "" && phone == null) {
return false;
}
if (phone!= "") {
var phoneValue =phone.value;
alert(phoneValue);
var p1 = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
var reg0 = /^13\d{5,9}$/;
var reg1 = /^153\d{4,8}$/;
var reg2 = /^159\d{4,8}$/;
var reg3 = /^0\d{10,11}$/;
var me = false;
if (p1.test(phoneValue)||reg0.test(phoneValue)||reg1.test(phoneValue)||reg2.test(phoneValue)||reg3.test(phoneValue))
me = true;
if (!me) {
phone.value = '';
document.getElementById("checkPhoneDiv").style.display = "block";
phone.focus();
return false;
}
else
{

document.getElementById("checkPhoneDiv").style.display = "none";

}
}
document.getElementById("regForm").submit();
alert(document.getElementById("regForm"))
}

</script>
<style type="text/css">
.checkUser {
font-size: 20px;
color: red;
font-family: "华文行楷";
text-algin: center;
}
</style>
<style type ="text/css">
.checkPhone {
font-size: 20px;
color: red;
font-family: "华文行楷";
text-algin: center;
}
</style>

</head>
<body>
<form id="regForm" name="friendAction" method="post" action="friend/friendaction!save">
<table>
<tr>
<td>
姓名:
</td>
<td>
<input id="name" type="text" name="name" οnblur="CheckName()"/>
</td>
<td>

<div id="checkUser1111" class="checkUser"><span >
</span></div>

<div id="checkUserDiv" style="display: none">
<span id="checkUser" class="checkUser" >
由4-16个英文字母、数字或下划线组成(不能以数字和下划线开头). </span>
</div>
</td>

</tr>
<tr>
<th>
性别:
</th>
<td>
<label>
<input name="sex" type="radio" id="sex_0" value="男"
checked="checked" />

</label>
<label>
<input type="radio" name="sex" value="女" id="sex_1" />

</label>
<br />

</td>
</tr>

<tr>
<td>
电话:
</td>
<td>
<input id="phone" type="text" name="phone" id="phone" />

</td>
<td>
<div id="checkPhoneDiv" style="display: none">
<span id="checkPhone" class="checkPhone" >
电话号码不合法! </span>
</div>
</td>
</tr>
<tr>
<td colspan="3" align="left">
<input type="button" value="保存" οnclick="dosave()" />
<input type="button" value="删除"/>
<input type="reset" value="重置" />
</td>
</tr>

</table>
</form>
</body>
</html>

cjsp/pcook.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>
<script type="text/javascript" language="javascript">


</script>
</head>
<body>
<form id="findfood" name="pcookAction"
action="pcookAction/pcookAction!findAll" method="post">
<table>
<tr>
<td>
<a> 参考食谱 </a>

</td>
</tr>
<tr align="left">
<td></td>
<td align="left">
<input type="text" name="name" />
<input type="submit" value="查询" />
</td>
</tr>
<tr>
<td>
<a> <img src="../img/personCook_pic2.png" /> </a>
</td>
<td>
<img src="../img/personCook_pic2.png" />
</td>
<td>
<img src="../img/personCook_pic2.png" />
</td>
</tr>
<tr>
<td>
<img src="../img/personCook_pic2.png" />
</td>
<td>
<img src="../img/personCook_pic2.png" />
</td>
<td>
<img src="../img/personCook_pic2.png" />
</td>
</tr>
<tr>
<td>
<a><img src="../img/personCook_pic2.png">
</a>
</td>
<td>
<img src="../img/personCook_pic2.png" />
</td>
<td>
<img src="../img/personCook_pic2.png" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td colspan="3" align="left">
<input type="button" value="添加" />
<input type="button" value="完成" />
</td>
</tr>
</table>
</form>
</body>
</html>
OK 搞定 适合新手学习 贴的累死了 不懂可以留言问我 数据库自己看着字段配置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值