本文目录一览:
- 1、jsp+ssh编程
- 2、需要一个可以运行的JSP简单代码?
- 3、初学jsp中的ssh框架
- 4、求ssh2 项目代码(特别是一定要有购物车,或者单纯的购物车和jsp也可以参考)
- 5、SSH问题:管理添加页面/web-root/jsp/admin/admin_insert.jsp代码如下:
- 6、求一个jsp代码实现登录,验证消息就为用户名和密码
jsp+ssh编程
@1f89f1d4这是内存地址
list.size() 0 就代表用户名和密码同时正确(username不能重复的情况)
需要一个可以运行的JSP简单代码?
%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%
%
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%"
titleMy JSP 'index.jsp' starting 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
This is my JSP page. br
/body
/html
初学jsp中的ssh框架
这么跟你说吧,SSH 是3个框架,一个是管和数据库打交道的,就是存数据,取数据的,是其中的H,即hibernate。
一个是管业务的,即struts2,也就是比如你在网页点一个按钮,后面应该给你显示那些数据,而这个时候,hibernate只管查,而怎么去查,是struts2管的。
一个是开源的框架,即spring,这个家伙主要是作用是依赖注入,说白点,就是你的程序里不需要出现任何常量,比如new Student() ,比如"hello" 等等 ,这些都可以靠配置文件来搞定了。
比如说你写了个字符串 ,是hello,后来你要改,要byebye了,如果没有依赖注入的话,你要去改程序的,打开程序,把hello改成byebye,这样的话就不好了,有了spring,你改个配置文件,搞定!具体怎么改的,在哪写的,这些我就不是一两句能说清楚了,而且我这也只是举个例子。
另外spring还给很多框架提供了支持,什么叫提供支持,就是spring里面有这些框架的支持类,你可以直接用,比如hibernate,就有这么一个类,hibernateDaoSupport,比如struts2,就有这么一个类ActionSupport。当然 还有其他很多现成的,写好的类给你用。
这就是叫提供支持!
我觉得我说的够白话了吧。
最后说说框架和设计模式,设计模式是一种设计的理念,说白点,设计模式就是模式,没有代码。
而框架,是已经写好的,具有一定功能的代码,框架一般都封装了很多现成的类,你可以直接使用,非常方便。
希望对你有帮助。
求ssh2 项目代码(特别是一定要有购物车,或者单纯的购物车和jsp也可以参考)
我以前做过,很全的一个!你找下你需要的代码吧,
//发票集合 id
public static int receiptids;
//购物车集合Linked
public static MapString ,Goodslist ShoppingMap =null;
//获取集合
public MapString, Goodslist getShoppingMap() {
if(ShoppingMap==null){
//System.out.println("get==null");
return ShoppingMap=new HashMapString,Goodslist();
}else{
return ShoppingMap;
}
}
public void setShoppingMap(MapString, Goodslist shoppingMap) {
ShoppingMap = shoppingMap;
}
//添加商品
public void addBookMap(Goodslist shoop){
if(ShoppingMap==null){
ShoppingMap=new HashMapString,Goodslist();
ShoppingMap.put(shoop.getGname(),shoop);
}else{
this.ShoppingMap.put(shoop.getGname(),shoop);
}
System.out.println(ShoppingMap.size());
}
//删除集合中的key
public void remBookMap(String key){
if(this.ShoppingMap.containsKey(key)){
this.ShoppingMap.remove(key);
}
}
//获取商品集合
public Goodslist getBookMap(String key){
return (Goodslist)this.ShoppingMap.get(key);
}
//购物车管理
public MapString ,Goodslist ManagerAddShopping(Goodslist goodslist){
//添加购商品到购物车
String goodsName=goodslist.getGname();
if(goodslist!=null){
if(this.getShoppingMap().containsKey(goodsName)){
//得得单个商品数量 //如果有则加一
int count=ShoppingMap.get(goodsName).getGnumber();
ShoppingMap.get(goodsName).setGnumber(count+1);
//得到单个商品总价
ShoppingMap.get(goodsName).setSubtotal(goodslist.getPrice()*(count+1));
}else{
System.out.println("新添加商品到购物车");
//添加一个商品集合到购物车
this.addBookMap(goodslist);
}
return ShoppingMap;
}
return null;
}
//修改数量
public void updateShopping(String key,int number){
System.out.println("key"+key+number);
if(this.getShoppingMap().containsKey(key)){
//加
if(number0){
//得得单个商品数量 //如果有则加一
//int count=ShoppingMap.get(key).getGnumber();
ShoppingMap.get(key).setGnumber(number);
//得到单个商品总价
ShoppingMap.get(key).setSubtotal(ShoppingMap.get(key).getPrice()*(number));
}
}
}
//计价
public double getSumPirce(){
double sumMoney=0;
if(this.ShoppingMap.size()0){
for(Map.EntryString, Goodslist entry : ShoppingMap.entrySet()) {
System.out.println(entry.getKey());
sumMoney=sumMoney+ShoppingMap.get(entry.getKey()).getSubtotal();
}
/*Iterator it =ShoppingMap.keySet().iterator();
while(it.hasNext()){
String key=(String)it.next();
}
*/
}
return sumMoney;
}
//模糊搜索
public List getSerch(String name){
List list=null;
if(name.isEmpty()){
System.out.println("Manager.getSerch() return null");
return null;
}else{
//list=imples.getSeachResults(name);
return list;
}
}
/*
*读取 订单人的收货地址 根据会员id
*/
public ListMemberdatas getConsigneeInfo(int id){
String sql="from Memberdatas where MId="+id;
return ExcuteSQL.executQuery(sql, null);
}
/*
*读取 订单人的收货地址 根据编号
*/
public ListMemberdatas getConsigneeInfoID(int id){
String sql="from Memberdatas where miId="+id;
return ExcuteSQL.executQuery(sql, null);
}
/*
*读取 订单人的商品集合
*/
public ListGoods getConsigneeGoods(){
return null;
}
/*
*读取 订单人的发票信息
*/
public ListReceipt getReceipt(int meberID){
String sql="from Receipt where OId="+meberID;
return ExcuteSQL.executQuery(sql, null);
}
/*
*插入 订单人的收货地址
*/
public boolean inisertConsigneeInfo(Memberdatas memberdatas){
boolean b=ExcuteSQL.save(memberdatas);
return b;
}
//删除收货人地址
public boolean delectMebreAddes(int mid){
String sql="delete Memberdatas where miId="+mid;
//System.out.println("ManagerOrder.delectMebreAddes()="+mid);
int count=ExcuteSQL.executUpdate(sql, null);
if(count0){return true;}else{ return false;}
}
//修改收货人地址
public boolean updateAdders(int mlid,String [] whe){
//String sql="update Memberdatas set names=?,adders=?, phone=? , phones=? where miId="+mlid;
String sql="update Memberdatas set names='"+whe[0]+"',adders='"+whe[1]+"', phone='"+whe[2]+"', phones='"+whe[3]+"' where miId="+mlid;
int count=ExcuteSQL.executUpdate(sql, null);
if(count0){return true;}else{ return false;}
}
//修改发票
public boolean updateReli(int ids,String rname, String rtype){
String sql="update Receipt set rtype='"+rtype+"' ,retop='"+rname+"' where ids="+ids;
int count=ExcuteSQL.executUpdate(sql, null);
if(count0){return true;}else{ return false;}
}
//添加发票
public boolean insertReli(Receipt re){
return ExcuteSQL.save(re);
}
//插入商品列表
public boolean insertGoodsList(Goodslist golist)
{
return ExcuteSQL.save(golist);
}
//临时商品集合 从购物车中取出的商品
public static ListGoodslist TempList;//=new ArrayListGoodslist();
public void addTempList(Goodslist go){
if(TempList==null){
TempList=new ArrayListGoodslist();
}
TempList.add(go);
}
public ListGoodslist getTempList() {
if(TempList==null){
return TempList=new ArrayListGoodslist();
}else{
return TempList;
}
}
public void setTempList(ListGoodslist tempList) {
TempList = tempList;
}
public ListReceipt reList;
public ListReceipt getReList() {
if(reList==null){
return reList=new ArrayListReceipt();
}else{
return reList;
}
}
public void setReList(ListReceipt reList) {
if(reList==null){
reList=new ArrayListReceipt();
}
this.reList = reList;
}
public void addreList(Receipt re){
if(reList==null){
reList=new ArrayListReceipt();
}
reList.add(re);
}
//查询订单根据会员id
public ListGoodsOrader getOrder(int mid){
//先获取订单id
ListGoodsOrader listRetu=new ArrayListGoodsOrader();
Interfaces imp=new Imple();
List ids=imp.getOrderid(mid);
System.out.println("ManagerOrder.getOrder()"+ids);
if(ids!=null){
for(int i=0;iids.size();i++){
System.out.println("ManagerOrder.getOrder()ids.size()="+ids.size());
String sql="from GoodsOrader where orders.OId="+Integer.parseInt(ids.get(i).toString());
ListGoodsOrader list=ExcuteSQL.executQuery(sql, null);
for(GoodsOrader god:list){
//添加订单对象,
listRetu.add(god);
}
}
return listRetu;
}else{
return null;
}
}
//删除订单
public boolean deleteOrder(int oid){
String sql="delete GoodsOrader where orders.OId="+oid;
int b=ExcuteSQL.executUpdate(sql, null);
if(b0) return true;else return false;
}
}
-------------------------------------------------------------------------
package snail.su.rui.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import snail.su.manager.ManagerOrder;
import snail.su.vo.Goodslist;
public class UpdateShoop extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
//修改购物车
String shoopKey=request.getParameter("shoopKey");
String number=request.getParameter("number");
String shookeys=new String(shoopKey.getBytes("ISO-8859-1"),"gb2312");
ManagerOrder order=new ManagerOrder();
order.updateShopping(shookeys, Integer.parseInt(number));
request.getSession().setAttribute("buyNumber",order.ShoppingMap.size());
//计价
double sunMoney=order.getSumPirce();
out.print(sunMoney);
System.out.println("UpdateShoop.doPost()"+sunMoney);
}
}
-----------------------------------------------------
//删除购物车里的物品
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
String key=request.getParameter("key");
key=new String(key.getBytes("ISO-8859-1"),"utf-8");
ManagerOrder orader=new ManagerOrder();
orader.remBookMap(key);
request.getSession().setAttribute("buyNumber",orader.ShoppingMap.size());
//获取商品集合到购物车
ManagerOrder order =new ManagerOrder();
MapString ,Goodslist shoopMap=order.getShoppingMap();
//添加集合到session
HttpSession ShoopSession=request.getSession();
ShoopSession.setAttribute("SUshoopMap",shoopMap);
System.out.println(shoopMap.size());
//把session写入到cookie里面
if(ShoopSession!=null){
System.out.println("写入session到了cookie了!");
Cookie cookie=new Cookie("JSESSIONID",ShoopSession.getId());
cookie.setMaxAge(60*60*24);
response.addCookie(cookie);
}
request.getRequestDispatcher("WEB-INF/rui/myShoop.jsp").forward(request, response);
}
SSH问题:管理添加页面/web-root/jsp/admin/admin_insert.jsp代码如下:
在你的struts.xml中相应的action标签中加一属性method="insert"
action
method="insert"
attribute="adminForm"
input="/jsp/errors.jsp"
name="adminForm"
parameter="status"
path="/jsp/admin/admin"
scope="request"
type="org.lxh.myzngt.struts.action.AdminAction"
forward name="insertdo" path="/jsp/admin/admin_insertdo.jsp"/forward
forward name="list" path="/jsp/admin/admin_list.jsp"/forward
forward name="updatepwddo" path="/jsp/admin/admin_updatepwd_do.jsp"/forward
forward name="deletedo" path="/jsp/admin/admin_delete_do.jsp"/forward
/action
一般action都会继承ActionSupport,所以会默认执行excute方法,我们的逻辑处理一般会写在action中这个重写的方法内,你如果要用其他方法就需要在xml中说明
求一个jsp代码实现登录,验证消息就为用户名和密码
你是想用那种方法实现呢? 是单单 jsp+javabean 还是 jsp+struts2 还是 ssh 框架?先给你个 jsp+struts2 的例子吧,我之前做过的,你只用看对你有用的部分
//登录页面,form 表单
s:form action="deng" method="post"
table
tr
tdimg src="image/bg4.jpg" height="550" width="450" border="0"/td
td
fieldset style="width: 260px; height: 190px;"
legendh2会员登录/h2/legend
姓 名:input type="text" name="name"/br/br/
密 码:input type="password" name="password"/br/br/br/
input type="submit" value="登 录"
s:a href="regist.jsp"立即注册/s:a/fieldset
/td
/tr
/table
/s:form
//配置 struts.xml 文件
package name="mu" extends="struts-default"
!-- 会员登录 --
action name="deng" class="action.LoginAction" method="loginUser"
result/user_first.jsp/result
result name="failure"/login.jsp/result
/action
/package
//下面是处理的 action :
package action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import dbOperate.AdminDAO;
import dbOperate.UserDAO;
@SuppressWarnings("serial")
public class LoginAction extends ActionSupport {
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
//会员登录
public String loginUser()
{
if((new UserDAO()).login_Action(name,password))
{
ActionContext ac = ActionContext.getContext();
ac.getSession().put("username", name);
return SUCCESS;
}
else
{
this.addActionError("用户名或密码错误,登录失败!");
return "failure";
}
}
//管理员登录
public String loginAdmin()
{
if((new AdminDAO()).login_Action(name, password))
{
ActionContext ac = ActionContext.getContext();
ac.getSession().put("username", name);
return SUCCESS;
}
else
{
this.addActionError("用户名或密码错误,登录失败!");
return "failure";
}
}
}
//下面是处理的 java 类
package dbOperate;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import bean.RegUser;
public class UserDAO {
DbConnection dbConnect = null;
Connection con = null;
java.sql.PreparedStatement ps = null;
private RegUser user;
public RegUser getUser() {
return user;
}
public void setUser(RegUser user) {
this.user = user;
}
//会员登录
public boolean login_Action(String name,String password)
{
boolean b = false;
ResultSet rs = null;
try
{
dbConnect = new DbConnection();
con = dbConnect.getConnection();
String sql = "select password from reguser where name = ?";
ps = con.prepareStatement(sql);
ps.setString(1,name);
rs = ps.executeQuery();
while(rs.next())
{
if(rs.getString("password").equals(password))
b = true;
}
}
catch (Exception e)
{
System.out.println("出错信息:"+e.getMessage());
}
finally
{
try {
if (con!=null)
con.close();
} catch (Exception e2) {}
}
return b;
}
}
希望对你有帮助