找到一个ajax的小工具DWR,
现在有点麻烦的是
在Server端提供服务方法的那个类里 怎么取得当前web应用的相关数据
例如session
哎,烦死了,搞半天
现在有点麻烦的是
在Server端提供服务方法的那个类里 怎么取得当前web应用的相关数据
例如session
哎,烦死了,搞半天
解决方案 »
- 在线等!!!ejb+jboss的项目启动报错!!高分!!!
- 请教javax.servlet.ServletException: Could not initialize class
- socket编程 accept()异常
- 面试中问到的有关Struts的ActionForm的问题
- java输出数据类型是float 时, 数据变了,该如何处理?
- 可以直接下个BBS和自己的网站相连吗?
- tomcat启动了。但是在地址栏输入:http://localhost:8080并没有出现欢迎界面?为何??
- #####一页要提交两个表单的相关问题。应该很简单吧。在线。#####中午以前最好。
- 请教jsp不支持中文问题??
- 请问在TOMCAT下面怎么样配置存放运行SERVELET的路径?
- 验证码生成是怎做的?
- 请教各位大哥一个关于STRUTS中客户化标签里的out.println()相关的问题!
import org.directwebremoting.WebContextFactory; WebContext wctx = WebContextFactory.get();使用这个ctx应该就可以获取到session和request等
/**
* Class to enable us to access servlet parameters.
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public interface WebContext extends ServerContext
{
/**
* Get the script session that represents the currently viewed page in the
* same way that an HttpSession represents a cookie.
* @return A browser object for this user
*/
ScriptSession getScriptSession(); /**
* What is the URL of the current page.
* This includes 'http://', up to (but not including) '?' or '#'
* @return The URL of the current page
*/
String getCurrentPage(); /**
* Returns the current session associated with this request, or if the
* request does not have a session, creates one.
* @return Returns the http session.
* @see HttpServletRequest#getSession()
*/
HttpSession getSession(); /**
* Returns the current HttpSession associated with this request or, if
* there is no current session and create is true, returns a new session.
* If create is false and the request has no valid HttpSession, this method
* returns null.
* @param create false to return null if there's no current session
* @return the session associated with this request
* @see HttpServletRequest#getSession(boolean)
*/
HttpSession getSession(boolean create); /**
* Accessor for the http request information.
* @return Returns the request.
*/
HttpServletRequest getHttpServletRequest(); /**
* Accessor for the http response bean.
* <p>You can't use this request to directly reply to the response or to add
* headers or cookies.
* @return Returns the response.
*/
HttpServletResponse getHttpServletResponse(); /**
* An attribute used by {@link WebContext#forwardToString(String)} to inform
* anyone that wants to know that this is a request from DWR.
*/
public static final String ATTRIBUTE_DWR = "org.directwebremoting"; /**
* Forward a request to a given URL and catch the data written to it.
* It is possible to distinguish requests that arrive normally and requests
* that come from a DWR forwardToString() by the presence of a request
* attribute. Before the request is forwarded, DWR will call:
* <pre>
* request.setAttribute(WebContext.ATTRIBUTE_DWR, Boolean.TRUE);
* </pre>
* @param url The URL to forward to
* @return The text that results from forwarding to the given URL
* @throws IOException if the target resource throws this exception
* @throws ServletException if the target resource throws this exception
* @throws IllegalStateException if the response was already committed
*/
String forwardToString(String url) throws ServletException, IOException; /**
* For system use only: This method allows the system to fill in the session
* id and page id when they are discovered.
* @param page The URL of the current page
* @param scriptSessionId The session id passed in by the browser
*/
void setCurrentPageInformation(String page, String scriptSessionId);
}
//例子供参考
public List getList(String name,ServletContext cx) {
HttpServletRequest request = null;
WebContext ctx = WebContextFactory.get();
HttpSession s = ctx.getSession();
request = ctx.getHttpServletRequest();
String name = request.getParameter("name");
}
通过WebContextFactory.get();方法
取得一个WebContext的对象,就可以取得request和response了...接下的的就no problem了!!!!