SSH integrated login case

I used Structs the most in the past, but I didn’t get involved with Spring and Hibernate. Recently, I made a small case of user login and integrated SSH. Originally, I used Ajax to handle the information transfer in the front desk. Use it, improve it and post it later. I summed up the integration steps of SSH and some situations encountered in the development case.

One: How to integrate SSH

Integrating SSH is mainly done by using configuration files. This part of the integration steps is in the SSH integration I reproduced in the next article.

"SSH Integration Steps"

Two: Problems encountered in the development case

A problem when integrating Action into Spring is that Action always shows that it cannot be instantiated, and the page always pops up:

Unable to instantiate Action error, find data and find that there are three possibilities

1. It's a spelling error, which should be checked carefully by yourself

2. Error in configuration file:

Start Action in my structs.xml file

<action name="login"class="com.demo.action.LoginAction">
<exception-mapping exception="java.lang.Exception" result = "error" />
<result name = "success">/admin/index.html</result>
<result name = "error">/admin/error.jsp</result>
</action>

Configuration in the applicationcontext.xml file:

<bean id="loginAction"class="com.demo.action.LoginAction"scope="prototype">
<property name="userManager" ref="userManager"></property>
</bean>

This is wrong. Since the action is to be integrated into spring, the action is handed over to the spring controller. The class in the action should correspond to beanid="loginAction" in applicationcontext.xml, that is to say, class= "loginAction" should be used. Replace com.demo.action.LoginAction" with class="loginAction", the class in action corresponds to the id in the bean

3. This kind of error is hard to spot for us beginners

I wrote two sentences like this in LoginAction

HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();

People who understand the principle of ServletDispatcher in webwork may know the reason, because ServletDispatcher accepts HTTP requests from clients, wraps many related objects of JavaServlet, and then passes them to our XWork framework, which parses our xwork.xml configuration. file, according to the information of the configuration file, create the corresponding Action, assemble and call the corresponding interceptor, execute the Action, and return the execution result.
Therefore, each client request will call the service() method of ServletDispatcher.
The execution order of this method is as follows:
1. Obtain the action namespace through the request request.
2. According to the Path requested by the servlet, resolve the name of the Action to be called. (actionName)
3. Create an Action context (extraContext)
4. Create an ActonProxy according to the namespace, actionName, and extraContext obtained earlier.
5. Execute the execute() method of the proxy, and call and execute the corresponding Result (return) according to the value returned by the Action execution. result processing).
It should be understood now that the Action object instance is created before the ActionContext object instance, so getting the ActionContext container object in this way may return null. (This passage is quoted from: http://blog.csdn.net/icejadelove /article/details/4764399)

The solution, I searched for information and found several methods of obtaining request, response, and session in "structs2" which I reproduced.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326987700&siteId=291194637
Recommended