Note

本文详细解析了HTTP请求的GET与POST方法在Servlet中的处理机制,包括服务方法和服务处理的区别,中文乱码问题的解决策略,不同页面间数据共享的方式如Cookie、Session和表单隐藏域,以及分页显示的实现步骤。同时,对比了Cookie和Session的使用场景与区别,并介绍了单例模式的应用,以及在Servlet中处理中文乱码的方法。此外,还涉及了在Action类中接收参数、处理中文乱码问题、使用Struts标签库、JSP页面加入标签库、拦截器配置、Android下JUnit测试框架配置、Hibernate对象状态、SessionFactory使用、字节流与字符流的概念,以及RandomAccessFile类的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

service()和doget(),dopost()方法的区别

  不管是post还是get方法提交过来的连接,都会在service中处理,然后,由service来交由相应的doPost或doGet方法处理,如果你重写了service方法,就不会再处理doPost或doGet了。

  get请求和post请求结构不同:get请求的参数在地址栏中,这就造成了两个后果,1.参数不能太多(受到限制),2.若参数是敏感信息,则不安全。而post请求因为参数是写在请求体中的,所以不会出现这样的情况。( 但也造成了用户不能添加书签等后果)

 

中文乱码问题处理:

   req.setCharacterEncoding("UTF-8");(在取得任何参数之前)

String staName =new String(staName.getBytes("iso-8859-1","utf-8"));

 

不同页面间数据共享:
 
  1.cookie
      Cookie cookie = new Cookie(名称,值);(创建Cookie)
      cookie.setMaxage(14*24*60*60);(设置存活时间)
      res.addCookie(cookie);(回写到客户端)
  2.session
      HttpSession session = request.getSession();(得到session)
      session.setAttributte();(向session中添加属性)
      session.getAttributte();(在另一个页面获得session中的属性)
  3.表单隐藏域
    
  4.res.sendRedirect()
      res.sendRedirect("sectionlist?sectionID = 2");

分页显示的实现:

  先定义4个变量
  pageSize(每页显示多少条记录)
  pageNow (希望显示第几页)
  rowCount (一共查询到多少条记录)
  pageCount (一共有多少页)
   
   步骤:
           1.得到rowCount:  来凝结数据库,从数据库中查询
           2.计算pageCount:
                              if(rowCount%pageSize==0){
                                     pageCount = rowCount/pageSize;
                                     }
                                     else{
                                     pageCount = rowCount/pageSize+1;
                                      }
          3.显示超链接:
          4.动态的接收pageNow:
                 
                 String pageN = req.getParameter("pageNow");
                  if(pageN!=null){
                       pageNow = Integer.parseInt(pageN);
                       }

Cookie和Session的区别:
    Cookie保存在客户端,而Session保存在服务器。所以,Session比Cookie安全。
    生存时间计时不同(Cookie累计计时,Session间隔计时)

ServletContent


<input type="text" name="staId" size=20 onfocus="this.value''" value="请输入关键字"/>

//接收到的数值都是String型的,得把它转换成int型
String staDeptId = request.getParameter("staDeptId");
Integer.parseInt(staDeptId);

单例模式:
//本类中new一个实例 
private static Forum finstance ;
 public static Forum GetInstance()
 {
  if(finstance==null)
   finstance=new Forum();
  return finstance;
 }
 private Forum(){}
//其他类中调用
Forum fm= Forum.GetInstance();

//注册时对密码加密
public void setPassWord(String passWord) {  
  try {
   //注册的时候调用JDK自带的加密函数,把密码加密后在存入数据库
   MessageDigest  sha=MessageDigest.getInstance("SHA");
   this.passWord=new String(sha.digest(passWord.getBytes()));
  } catch (NoSuchAlgorithmException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }


E:\\新建文件夹 (3)\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\CompanyManagement\\

____________________________________________________________

 

把属性放在Action外的bean类里,调用属性时的格式为user.username,user.password
——————————————————————————————————————————

获取绝对路径:
<%
String path=request.getContextPath();
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+path+"/";
%>
————————————————————————————————————————————————————
 public void execeute()
 { 
           String name = super.getRequest().getParameter("paraName");  //在Action类中也可以用这种方法接收参数,不过要用super
         System.out.println("姓名:" + name); 
 } 

————————————————————————————————————————————————————
Action怎么处理中文乱码问题:
在struts.xml这要写
<constant name="struts.i18n.encoding" value="GBK" /> 
——————————————————————————————————————————————————————
jsp页面加入struts标签库<%@taglib uri="/struts-tags" prefix="s" %>
——————————————————————————————————————————————————

       拦截器的配置无非就是声明拦截器、引用拦截器以及声明拦截器栈。可以认为拦截器栈是由多个拦截器组成的一个大的拦截器。
       定义拦截器和拦截器栈都在<interceptors />这个标记内
       以下是一个例子:
       <interceptors>
              <interceptor name=”log” class=”cc.dynasoft.LogInterceptor” />
<interceptor name=”authority” class=”cc.dynasoft. Authority Interceptor” />
<interceptor name=”timer” class=”cc.dynasoft.TimerInterceptor” />
<interceptor-stack name=”default”>
       <interceptor-ref name=” authority” />
<interceptor-ref name=” timer” />
</interceptor>
————————————————————————————————————————————————————————
引用拦截器是在action中引用的:例子:
<action name=”login” class=”cc.dynasoft.LoginAction”>
       ……
       <interceptor-ref name=”log” />
</action>
——————————————————————————————————————————————————

Android下junit测试框架的配置:
1.新建一个类(继承AndroidTestCase )
2.在Manifest.xml文件里配置
——————————————————————————————————————————————————————

Hibernate PO对象的状态:
临时态:刚new出来的对象是临时状态的,或者把持久态的对象delete(),则会成临时态
持久态:在数据库中有对应记录(save())
脱管态:
————————————————————————————————————————————————————————
SessionFactory.getCurrentSession与openSession的区别:
前者commit后session会自动关闭;后者需要手动关闭session.close()。
————————————————————————————————————————————————————
字节流:以字节为单位进行IO操作
最大的两个父类是 InputStream(对应read)与OutputStream(对应write)

字符流:
最大的两个父类为 Writer和Reader这两个抽象类
_________________________________________________________________________________________

RandomAccessFile类:随机访问文件

输入流FileInputStream和输出流 FileOutputStream,实现的是对磁盘文件的顺序读写,而且读写要分别创建不同对象。相比之下RandomAccessFile类则可对文件实现随机读写操作。

RandomAccessFile对象的文件位置指针遵循下面的规律:

·新建RandomAccessFile对象的文件位置指针位于文件的开头处;

·每次读写操作之后,文件位置的指针都相应后移到读写的字节数;

·可以通过getFilePointer方法来获得文件位置指针的位置,通过seek方法来设置文件指针的位置。
——————————————————————————————————————————————————————
<bean id=”……” class=”……”> 
       <property name=”属性1” value=”……”/> 
       <property name=”属性2” value=”……”/> 
       …… 
</bean> 
这种只要在相应的类中提供set方法就可以实现了。

<bean id=”……” class=”……”> 
       <constructor-arg>构造函数需要的参数1</constructor-arg> 
       <constructor-arg>构造函数需要的参数2</constructor-arg> 
       …… 
</bean> 
这种得在相应的类中写有参数的构造函数,才能实现

 

 

 

 


 

03-21
### Note Application or Functionality in IT Context In the IT context, a note application refers to software designed for creating, organizing, and managing textual information such as notes, lists, reminders, etc. These applications often provide features like real-time synchronization across devices, tagging, categorization, searchability, and sometimes integration with other productivity tools. The concept of sharing working objects between application components at runtime can be directly related to how modern note-taking apps function[^1]. For instance, these applications may use shared memory spaces or inter-process communication mechanisms to ensure seamless interaction among different parts of an app while maintaining performance efficiency. Additionally, when debugging complex systems involving graphical user interfaces (GUIs), libraries similar to Inspector—a Qt-based tool—can play crucial roles by allowing interactive inspection into lower levels of data models used within those GUI frameworks[^2]. Such capabilities are essential during development phases where understanding internal states becomes necessary for resolving issues effectively. Regarding Android-specific implementations mentioned through LayoutInflater example provided earlier[^3], it demonstrates one way contexts might influence layout inflations which indirectly affects UI elements rendering including potential custom views representing individual 'notes'. Here's simplified code snippet showing basic usage pattern: ```java // Example demonstrating typical utilization scenario. public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Obtain reference via system service method call. LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.activity_main, null); setContentView(view); } } ``` This piece illustrates obtaining `LayoutInflater` object using its factory method tied closely to current activity lifecycle state represented here symbolically under term **context**, thus affecting overall behavior dynamically based upon varying conditions present throughout execution period.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值