我正在实现自己的身份验证机制,我想知道我在做什么是正确的,如果不是我怎么能正确地做到这一点.
首先解释我的身份验证机制如何工作:
- 我的用户的详细信息位于名为Role的对象中.该对象包含3个字段:
电子邮件:String
密码:String
用户类型:Enum
- 当用户访问系统时,对象Role将保存到会话中.
我的问题是:如何根据userType字段限制对用户(角色)访问某些页面?
这是我做但不起作用.
首先我有一个托管bean来检查usser是否被记录.
@ManagedBean
@RequestScoped
public class SecurityController {
//Some attributes...
public String redirectNotBuyer() {
Role role = (Role) FacesContext.getCurrentInstance()
.getExternalContext().getSessionMap().get("userRole");
//Checks if user is logged
if (role == null) {
// Please login
//Add message to authentification
return "login.xhtml";
} else if (role != null) {
if (!role.getType().toString().equalsIgnoreCase("BUYER")) {
// Buyer not authorized
return "main.xhtml";
}
}
return null;
}
public String redirectNotSeller() {
Role …Run Code Online (Sandbox Code Playgroud) 我刚从Visual Studio 2005收到此消息,当我点击删除命令时,我使用界面配置网格添加到我的gridview:
除非指定了DeleteCommand,否则数据源'transactionsSqlDataSource'不支持删除.
我怎么能激活它?我希望我的用户在单击"删除"按钮时能够删除一行.
我已经将我的SQLDataSource的属性DeleteCommandType更改为StoredProcedure.我还需要做什么?
UPDATE
这就是我所做的,但我遗漏了一些东西,我无法编译:
这就是我在.cs所做的:
public string DeleteCommand { get; set; }
Run Code Online (Sandbox Code Playgroud)
我怎么能解决这个问题,它说得到的是身体缺失.我不习惯使用ASP.NET.你能帮我修一下这部分代码吗?
这就是我在.aspx所做的:
<asp:SqlDataSource ID="transactionsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:membershipsDBConnectionString %>"
SelectCommand="SELECT [brukerId], [kjoptekvoten], [pengeneutbetalt], [fyringsolje], [biltype], [kjoptid] FROM [Informasjon]" DeleteCommandType="StoredProcedure"
DeleteCommand="DELETE FROM [Informasjon] WHERE fyringsolje='Kull: 2,42 kg';">
</asp:SqlDataSource>
Run Code Online (Sandbox Code Playgroud)
数据源的配置是否正确?不要担心,如果你看到删除命令不使用上面的参数,它只是一个功课(我只需要通过查询).
更新2 我一直在尝试,但我无法解决它.我是ASP.NET的新手,我对所有术语都不是很熟悉.到底发生了什么?我如何知道我的商店程序的名称?:
CS:
public string DeleteCommand { get { return DeleteCommand; } set { DeleteCommand = "";}
Run Code Online (Sandbox Code Playgroud)
ASPX:
<asp:SqlDataSource ID="SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:membershipsDBConnectionString %>"
DeleteCommandType="StoredProcedure" SelectCommand="SELECT [id], [kjoptekvoten], [pengeneutbetalt], [fyringsolje], [biltype], [kjoptid] FROM [Informasjon]"
DeleteCommand="StoredProcedureName">
</asp:SqlDataSource>
Run Code Online (Sandbox Code Playgroud)
当我单击Delete时,需要从表 …
string sql2 = "SELECT SUM(fyringsolje) FROM Informasjon WHERE fyringsolje='Kull: 2,42 kg';";
SqlCommand myCommand2 = new SqlCommand(sql2, conn);
kullTotaltLabel.Text = "" + (int)myCommand2.ExecuteScalar();
Run Code Online (Sandbox Code Playgroud)
我没有看到标签的文字发生变化,恐怕查询不正确.我想确保查询是正确的!
我的一个客户不希望其他网站复制粘贴具体textArea的内容.目前我有一个inputTextArea为readonly ="true",但我仍然需要禁用复制和粘贴功能.有任何想法吗?
你能帮我找一下我的应用程序中登录方法的JPQL查询中的错误吗?
// Login
public boolean saveUserState(String email, String password) {
// 1-Send query to database to see if that user exist
Query query = em
.createQuery("SELECT r FROM Role r WHERE r.email=:emailparam r.password=:passwordparam");
query.setParameter("emailparam", email);
query.setParameter("passwordparam", password);
// 2-If the query returns the user(Role) object, store it somewhere in
// the session
Role role = (Role) query.getSingleResult();
if (role != null && role.getEmail().equals(email)
&& role.getPassword().equals(password)) {
FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().put("userRole", role);
// 3-return true if the user state was saved
return true; …Run Code Online (Sandbox Code Playgroud) 我使用javamail向用户发送帐户激活邮件.在该电子邮件中,有一个链接,当点击时,用户应激活他们的帐户,重定向到应用程序的主页并让他们登录.我怎么能这样做?我可以在我作为HTML模板发送的链接中添加对方法调用的方法调用吗?
这是我用于发送电子邮件模板的EJB:
@Stateless(name = "ejbs/EmailServiceEJB")
public class EmailServiceEJB implements IEmailServiceEJB {
@Resource(name = "mail/myMailSession")
private Session mailSession;
public void sendAccountActivationLinkToBuyer(String destinationEmail,
String name) {
// Destination of the email
String to = destinationEmail;
String from = "dontreply2thismessage@gmail.com";
try {
Message message = new MimeMessage(mailSession);
// From: is our service
message.setFrom(new InternetAddress(from));
// To: destination given
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject("Uspijesna registracija");
// How to found at http://www.rgagnon.com/javadetails/java-0321.html
message.setContent(generateActivationLinkTemplate(), "text/html");
Date timeStamp = new Date();
message.setSentDate(timeStamp);
// Prepare a multipart HTML
Multipart multipart …Run Code Online (Sandbox Code Playgroud) 我使用这个常规来验证我的java Web应用程序的许多输入字段:
"^[a-zA-Z0-9]+$"
Run Code Online (Sandbox Code Playgroud)
但我需要修改它,因为我有几个字段需要允许空格(例如:地址).
如何修改它以允许空格(如果可能的话不在开头).
我想我需要使用一些scape角色 \
我尝试了几种不同的组合,但没有一种有效.有人可以用这个正则表达式帮我吗?
一位大学的朋友正在使用挂毯框架学习网络编程,他问我能不能帮他完成作业.作业中的一个问题是:
什么是扩展,我们如何使用它?
这是第一次听到它.
你知道那个主题是什么吗?
我有点困惑.这个名字有没有OOP原则?
使用JAXB在Web服务上解组.xml时遇到问题.
这是从某个客户端发送到Web服务的.xml文件.
<?xml version="1.0" encoding="UTF-8"?>
<PERSON xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:/D:/MyWorkSpace/JAVA%20WEB%20Services%20DEVELOPER/XML%20Workspace/Persons.xsd">
<NAME>Michael</NAME>
<AGE>12</AGE>
<ADRESS>
<STREET>Somewhere in Spain</STREET>
<ZIP>47015</ZIP>
</ADRESS>
<HOBY indoorHoby="true"/>
</PERSON>
Run Code Online (Sandbox Code Playgroud)
这是解组的方法
@POST
@Path("/XMLArrivalBeacon")
@Consumes(MediaType.APPLICATION_XML)
public Response methodI(String content) {
System.out.print(content);
try {
//Unmarshaling
JAXBContext context = JAXBContext.newInstance(Person.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
//Unmarshal the String
Person person = (Person) unmarshaller.unmarshal(new StreamSource(new StringReader(content)));
//Checking that the values were recieved ok
System.out.print(person.getName());
return Response.ok("XML recieved from client!!!").build();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
这是使用JAXB注释注释的person类(从Schema自动生成)
package bindedschemas;
import java.math.BigInteger;
import javax.xml.bind.annotation.XmlAccessType; …Run Code Online (Sandbox Code Playgroud) 我想在字符串中找到所有负浮点数并将它们存储在数组中.我认为我的正则表达式是正确的,但我的方法有问题.
Pattern pattern = Pattern.compile("[-]?[0-9]*[.][0-9]+$");
String[] results = pattern.split("|AAA--A A05_#A| |-999.999| |-55.7|");
Run Code Online (Sandbox Code Playgroud)