java next语句_next关键字,在java里面哪里用到的?

展开全部

你的传32313133353236313431303231363533e59b9ee7ad9431333264653366值方法用反了,你上面的

表单里面写的方法是post但是你在后台Servlet处理的时候用的是doGet方法处理,是不可能接受到数据的。做这个上传东西的话,需要导入一些外包,像cosFir这种包来实现比较好一点。

如果只是实现提交功能的话,首先思路要明确,你表单的内容提交过来,要直接获取的话用你的方法就可以了,但是注意传值的方法,一般用post传值,因为get方法传值太小,容易丢失数据。还有就是你传过来了在servlet处理的时候最后弄个标记来处理,这样可以利用if分支来处理多个页面出来的的请求,当然servlet也只是初步的处理,你最后还得调用javabean来处理,就是你要用一个业务类来专门处理你的sql语句接串,然后提交数据可处理。看一下我写的一个登录的小程序:

登录页面:index.jsp

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

My JSP 'index.jsp' starting page

request.setCharacterEncoding("gbk");

String rs_flag=(String)request.getAttribute("rs_flag");

if(rs_flag!=null){

out.println(rs_flag);

}

%>

请登陆:

用户名:

密码:

servlet处理Loginservlet

package com.icss.contr;

import java.io.IOException;

import java.sql.SQLException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import com.icss.dao.UserDao;

public class LoginServlet extends HttpServlet {

/**

* Constructor of the object.

*/

public LoginServlet() {

super();

}

/**

* Destruction of the servlet.

*/

public void destroy() {

super.destroy(); // Just puts "destroy" string in log

// Put your code here

}

/**

* The doGet method of the servlet.

*

* This method is called when a form has its tag value method equals to get.

*

* @param request the request send by the client to the server

* @param response the response send by the server to the client

* @throws ServletException if an error occurred

* @throws IOException if an error occurred

*/

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

doPost(request,response);

}

/**

* The doPost method of the servlet.

*

* This method is called when a form has its tag value method equals to post.

*

* @param request the request send by the client to the server

* @param response the response send by the server to the client

* @throws ServletException if an error occurred

* @throws IOException if an error occurred

*/

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

/*

* servlet要完成用户提交信息的整理

*

*/

request.setCharacterEncoding("GBK");

String consumername=request.getParameter("consumername");

String consumerpsw=request.getParameter("consumerpsw");

int flag=0;

/*

* servlet要控制请求由那个业务类处理

*/

UserDao userdao=new UserDao();

try {

flag=userdao.validate(consumername, consumerpsw);

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

/*

* servlet 要根据业务类处理的结果(判断分支)选择响应的jsp页面

*/

if(flag==0){

/*

* 在响应之前在做显示信息的准备

*/

String rs_flag="登陆失败!请重试!";

request.setAttribute("rs_flag",rs_flag);

//转发

request.getRequestDispatcher("index.jsp").forward(request,response);

}else{

request.getRequestDispatcher("main.jsp").forward(request,response);

}

}

/**

* Initialization of the servlet.

*

* @throws ServletException if an error occurs

*/

public void init() throws ServletException {

// Put your code here

}

}

然后调用javabean业务处理类Userdao来处理

package com.icss.dao;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import com.icss.base.DbCon;

import com.icss.vo.UserVo;

public class UserDao extends DbCon {

public int validate(String consumername,String consumerpsw) throws ClassNotFoundException, SQLException{

getCon();

String sql="select * from consumer where consumername='"+consumername+"' and consumerpsw='"+consumerpsw+"'" ;

int flag=0;

ResultSet rs=DbCon.st.executeQuery(sql);

if(rs.next()){

flag=1;

}

rs.close();

closeCon();

return flag;

}

}

处理完数据库的接串以及查询以后返回结果到servlet做处理,然后返回jsp页面就可以了。

下面这个是连接数据库的,我不知道你用什么数据库,我用的是oracle,不过都差不多,你看一下把:

package com.icss.base;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class DbCon {

public static Connection conn=null;

public static Statement st=null;

public void getCon() throws ClassNotFoundException, SQLException{

Class.forName("oracle.jdbc.driver.OracleDriver");//创建数据库驱动对象

conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.207:1521:ICSS","TEST","MANAGER");//创建数据库连接对象

st=conn.createStatement();//创建执行sql语句对象

}

public void closeCon() throws SQLException{

if(st!=null){

st.close();

}

if(conn!=null){

conn.close();

}

}

/**

* @param args

*/

public static void main(String[] args) {

DbCon dbc=new DbCon();

try {

dbc.getCon();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

呼呼,写这个真是有点浪费时间~·不过好歹完工了,当作是复习一下。希望对你有用。。

追问

你这个同next关键字没有关联,不过还是要谢谢你!

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值