abszhanghe的专栏

记忆的共享

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

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

 

 

阅读更多
上一篇HQL语言入门
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭