用Web Services怎么样验证用户身份登陆? 我不知道怎么用,在网上看了好多,好像是在soaphandler中写.但我不知如何操作. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在数据库中验证用户名和密码,登录成功后把UserName设为Session变量request.getSession(true).setAttribute("userName",UserName);然后在需要进行登录用户识别时<%if (session.getAttribute("userName"==null)) {response.sendRedirect("login.jsp");}%>来验证 有很多种方法可以实现校验。1 基于tomcat角色认证。2 基于过虑器3 axis 与tomcat容器的session是共享,可以你也可以在你的业务层类里根据session进行校验4 基于handler的校验等等,很多种吧,你自己查一下资料。详细的我就不说了。 能不能说说基于handler的校验, 我现在做的Web Service都是可以在Windows应用程序发出SOAP请求,就可以返回值了。 如果我想实现身份认证,并且实现发送的信息加密,应该怎么做呢? MessageContext mc = MessageContext.getCurrentContext();Session session = mc.getSession();String name = (String)session.get("name");MessageContext 与 Session 是axis 中的类 别引用错了 csdn到底怎么了?怎么有一些菜鸟在这里发jsp里的session校验方法?jsp里的session与web services是一回事吗?还是我无知,有什么可以直接在jsp里写web services的方法?校验登陆可以用soap head,不过一些老的开发工具如delphi 7等调用你的web services时可能不支持自定义soap header,别的方法就是session了,不过这个session用jsp里的方法request.getSession是不可能的,没听说过在axis里写request.getSession,为了考虑在不同的web services框架里处理session的通用性,楼主可以看看xfire里取session的方法, 写个filter,让你在哪怕是javabean中都可以随便读取http请求信息 package com.test.web.filter;import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;/** * 处理字符转码,提供给Spring AOP或其它任何通过web请求加载的实例类中读取http相关信息 * @author peihexian */public class CommonFilter implements Filter { private FilterConfig config = null; private String defaultEncode = "UTF-8"; private static final String CHARSET_ENCODE_PARAM_NAME="Charset"; private static ThreadLocal<HttpServletRequest> requests = new ThreadLocal<HttpServletRequest>(); private static ThreadLocal<HttpServletResponse> responses = new ThreadLocal<HttpServletResponse>(); public static HttpServletRequest getRequest() { return (HttpServletRequest) requests.get(); } public static HttpServletResponse getResponse() { return (HttpServletResponse) responses.get(); } public static HttpSession getSession() { return (HttpSession) getRequest().getSession(); } public static HttpSession getSession(boolean create) { return (HttpSession) getRequest().getSession(create); } public void init(FilterConfig config) throws ServletException { this.config = config; if (this.config.getInitParameter(CHARSET_ENCODE_PARAM_NAME) != null) { defaultEncode = config.getInitParameter(CHARSET_ENCODE_PARAM_NAME); } } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ServletRequest srequest = request; srequest.setCharacterEncoding(defaultEncode); requests.set((HttpServletRequest) request); responses.set((HttpServletResponse) response); chain.doFilter(srequest, response); } public void destroy() { this.config = null; }} <filter> <filter-name>Common Filter</filter-name> <filter-class>com.test.web.filter.CommonFilter</filter-class> <init-param> <param-name>Charset</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>Common Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 以后在任何程序中,比如就是普通的javabean中要使用时 logger.debug(CommonFilter.getRequest().getRemoteHost()); 日,被request.getSession气晕了,上面的filter好像不是xfire里使用的取session的办法,有可能是dwr ajax framework里用的。 汗... 楼上的不是在说我吧说详细点import org.apache.axis.AxisFault;import org.apache.axis.MessageContext;import org.apache.axis.session.Session;MessageContext mc = MessageContext.getCurrentContext();Session session = mc.getSession();String name = (String)session.get("name");if(name == null){ throw new AxisFault("没登陆");} yyzh(答题容易分难得),确实是在说你!你的代码没有错! 但是此session和JSp里的session是两回事! peihexian(知其然.知其所以然)兄弟,用了你的CommonFilter,在客户端那里还是取不到Session,NullPointException,在Spring那里要配什么,AOP?能详细说说么?多谢了!!! 在客户端取IP?这个是用来在服务器端的web services程序里取客户端IP的,不是在web servcies的客户端取IP的。 to yyzh.我看了这篇文章:manage sessions in Web services.请问,用MessageContext , Session, 还要不要修改wsdd文件加SimpleSessionHandler?? http://www.ftponline.com/javapro/2003_04/online/wsdl_kjones_04_29_03/这是那篇文章 汗... 楼上的不是在说我吧说详细点import org.apache.axis.AxisFault;import org.apache.axis.MessageContext;import org.apache.axis.session.Session;MessageContext mc = MessageContext.getCurrentContext();Session session = mc.getSession();String name = (String)session.get("name");if(name == null){ throw new AxisFault("没登陆");}==================================axis 是运行在tomcat容器中,这样获取的session,是可以取得里面的变量的。你就看handler这部分的内容就行了! http://www.ftponline.com/javapro/2003_04/online/wsdl_kjones_04_29_03/这是那篇文章----------------this article is very good 你想用哪种模式啊~~是MODOU 1还是MODOU2 模式啊 xfire中增加handle就可以了,支持http认证,也可以使用SOAP头 Spring aop 关于around环绕通知几点疑惑 jsp单页面多表单在struts2那边应该怎么接受 分不多了 求高手帮忙 jqueryui 的dialog遮罩的问题 问一个问题? java调用删除存储过程出错?更新,插入都可以,高手看看有代码 刚学dom解释xml,有一小代码不是很懂,求指教 数据库中的数据如何实现多语 肯定给分!!!请问怎么在jbuilder9中创建消息资源文件 急急马上结:哪里有Tomcat下载,最好是4.0以上5.0以下!!! 编写BMP时遇到的困难,请赐教 告深圳程序员自白书 hibernate的Criteria可以进行嵌套查询么?
request.getSession(true).setAttribute("userName",UserName);然后在需要进行登录用户识别时
<%
if (session.getAttribute("userName"==null))
{response.sendRedirect("login.jsp");}
%>
来验证
1 基于tomcat角色认证。
2 基于过虑器
3 axis 与tomcat容器的session是共享,可以你也可以在你的业务层类里根据session进行校验
4 基于handler的校验等等,很多种吧,你自己查一下资料。详细的我就不说了。
如果我想实现身份认证,并且实现发送的信息加密,应该怎么做呢?
Session session = mc.getSession();
String name = (String)session.get("name");MessageContext 与 Session 是axis 中的类 别引用错了
package com.test.web.filter;import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;/**
* 处理字符转码,提供给Spring AOP或其它任何通过web请求加载的实例类中读取http相关信息
* @author peihexian
*/
public class CommonFilter implements Filter {
private FilterConfig config = null;
private String defaultEncode = "UTF-8";
private static final String CHARSET_ENCODE_PARAM_NAME="Charset"; private static ThreadLocal<HttpServletRequest> requests = new ThreadLocal<HttpServletRequest>();
private static ThreadLocal<HttpServletResponse> responses = new ThreadLocal<HttpServletResponse>(); public static HttpServletRequest getRequest() {
return (HttpServletRequest) requests.get();
} public static HttpServletResponse getResponse() {
return (HttpServletResponse) responses.get();
} public static HttpSession getSession() {
return (HttpSession) getRequest().getSession();
} public static HttpSession getSession(boolean create) {
return (HttpSession) getRequest().getSession(create);
} public void init(FilterConfig config) throws ServletException {
this.config = config;
if (this.config.getInitParameter(CHARSET_ENCODE_PARAM_NAME) != null) {
defaultEncode = config.getInitParameter(CHARSET_ENCODE_PARAM_NAME);
}
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
ServletRequest srequest = request;
srequest.setCharacterEncoding(defaultEncode);
requests.set((HttpServletRequest) request);
responses.set((HttpServletResponse) response);
chain.doFilter(srequest, response);
} public void destroy() {
this.config = null; }}
<filter>
<filter-name>Common Filter</filter-name>
<filter-class>com.test.web.filter.CommonFilter</filter-class>
<init-param>
<param-name>Charset</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter> <filter-mapping>
<filter-name>Common Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
以后在任何程序中,比如就是普通的javabean中要使用时 logger.debug(CommonFilter.getRequest().getRemoteHost());
说详细点import org.apache.axis.AxisFault;
import org.apache.axis.MessageContext;
import org.apache.axis.session.Session;MessageContext mc = MessageContext.getCurrentContext();
Session session = mc.getSession();
String name = (String)session.get("name");
if(name == null){
throw new AxisFault("没登陆");
}
这个是用来在服务器端的web services程序里取客户端IP的,不是在web servcies的客户端取IP的。
我看了这篇文章:manage sessions in Web services.
请问,用MessageContext , Session, 还要不要修改wsdd文件加SimpleSessionHandler??
这是那篇文章
说详细点import org.apache.axis.AxisFault;
import org.apache.axis.MessageContext;
import org.apache.axis.session.Session;MessageContext mc = MessageContext.getCurrentContext();
Session session = mc.getSession();
String name = (String)session.get("name");
if(name == null){
throw new AxisFault("没登陆");
}==================================
axis 是运行在tomcat容器中,这样获取的session,是可以取得里面的变量的。你就看handler这部分的内容就行了!
这是那篇文章
----------------
this article is very good