servlet读取web.xml中参数和页面转向方法

来源:互联网 发布:mac中safari下载视频 编辑:程序博客网 时间:2024/05/01 01:37

servlet读取web.xml中参数和页面转向方法

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Loginv1Servlet extends HttpServlet {
private String xmlName,xmlPass;
     protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
             throws ServletException, IOException {

         doPost(arg0, arg1);
     }

 
     public void init(ServletConfig config) throws ServletException {
         // 初始化时候对xml文档的内容进行读取   //这个是重写超类方法
        xmlName=config.getInitParameter("name");
        xmlPass=config.getInitParameter("pass");

        /*
         *      <init-param>
   
         * <param-name>pass</param-name>

         * <param-value>123456</param-value>
      
         *xml文件中的写法,写在<servlet> 块内
         * </init-param>
         */

    }
     protected void doPost(HttpServletRequest req, HttpServletResponse res)
             throws ServletException, IOException {
         //首先对客户端的数据流编码   解决中文问题
         req.setCharacterEncoding("GB2312");
         // 得到客户传递的数据
       
        String str= req.getParameter("action");
        String id=req.getParameter("id");
        String name=req.getParameter("name");
        String amount=req.getParameter("amount");
        res.setContentType("text/html;charset=gb2312");
        PrintWriter pw=res.getWriter();
        pw.println("<html>");
        pw.println("<title>准备购买的商品信息</title><body>");
        pw.println("编号:"+ id);
        pw.println("名称:"+ name);
        pw.println("数量:"+ amount);
    
        if("1".equals(str)){
            //电子支付
            pw.println("<a href='http://www.post.com.cn'target=_blank> 进入网上银行</a>"); 
        }else{
            //汇款
            pw.println("<a href='info.html'>填写详细信息</a>"); 
        }
        pw.println("</body>");
        pw.println("</html>");

     }
  
  
}

 


Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1798509

 

 

原创粉丝点击