Struts2 using the response and request functions

Source: Internet
Author: User

Struts.xml:

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.3//en" "http://struts.apache.org/dtds/ Struts-2.3.dtd "><struts><!--override Struts2 Some constants default value--    <constant name=" Struts.enable.DynamicMethodInvocation "value=" false "/>    <constant name=" Struts.devmode "value=" true "/ >    <constant name= "struts.action.extension" value= "Action,,do" ></constant>    <constant Name= "Struts.configuration.xml.reload" value= "true" ></constant>    <constant name= "Struts.locale" Value= "ZH_CN" ></constant><package name= "P1" extends= "Struts-default" ><action name= "Test1" class= "Com.itheima.actions.ActionDemo1" ></action></package></struts>

Actiondemo1.java:

Package Com.itheima.actions;import Java.io.ioexception;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.apache.struts2.interceptor.servletrequestaware;import Org.apache.struts2.interceptor.servletresponseaware;public class ActionDemo1 implements Servletresponseaware, Servletrequestaware{private httpservletresponse response;private httpservletrequest request;public String Execute () Throws ioexception{//Mode one://servletactioncontext.getresponse (). setContentType ("Text/html;charset=utf-8");// Servletactioncontext.getresponse (). Getwriter (). Write ("Hello");//Not struts does not work, does not use STRUTS2 for output////httpsession session = Servletactioncontext.getrequest (). getsession (); Response.setcontenttype ("Text/html;charset=utf-8"); Response.getwriter (). Write ("Eat"); return null;} public void Setservletresponse (HttpServletResponse response) {this.response = response;} public void Setservletrequest (HttpServletRequest request) {this.request = Request;}}

  

Struts2 using response and request features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.